To rename the branch you are on, run git branch -m new-name. For another branch, run git branch -m old-name new-name. Git cannot rename a branch on a remote, so push the new name with git push -u origin new-name, then delete the old one with git push origin --delete old-name.
| Situation | Command |
|---|---|
| Rename the current branch | git branch -m new-name |
| Rename a different branch | git branch -m old-name new-name |
| Overwrite an existing name | git branch -M old-name new-name |
| Publish the new name and track it | git push -u origin new-name |
| Remove the old name from the remote | git push origin --delete old-name |
| Fix a clone after someone else renamed it | git branch -u origin/new-name new-name |
Updated
Renaming locally is one command; the remote is where people get stuck, because a remote branch cannot be renamed in place, only replaced. Fill in the old and new names below to get the commands for your case, including what teammates must run afterwards and the extra steps when the branch is the GitHub default.
Renames locally, publishes the new name with tracking, then removes the old remote branch.
git switch feature/old-name
git branch -m feature/new-name
git push -u origin feature/new-name
git push origin --delete feature/old-nameThese are the steps GitHub lists for updating an existing clone, with the optional cleanup of stale remote branches.
git branch -m old-name new-name
git fetch origin
git branch -u origin/new-name new-name
git remote set-head origin -a
git remote prune origin
GitHub redirects web URLs containing the old name, moves branch protection to the new name, and retargets open pull requests and draft releases based on it. Raw file URLs are not redirected.
Writers can rename ordinary branches; renaming the default branch or a protected branch needs admin rights, and organisation rulesets can tighten that further.
Stick to lowercase letters, digits, hyphens and slashes for grouping, such as fix/login-timeout. Git rejects names with spaces, two dots in a row, a trailing dot or slash, a leading dash, or any of the characters ~ ^ : ? * [ and backslash.
Not with plain git. You push the branch under the new name and delete the old name. GitHub's web interface can rename a branch on the server, which also keeps pull requests and links working.
-m refuses if a branch with the new name already exists. -M is short for --move --force and replaces it. Neither will rename a branch that is checked out in another worktree of the same repository.
In the repository on GitHub, open Branches, choose rename on master, and type main. Renaming the default branch needs admin access. Then everyone runs the four commands GitHub shows: rename locally, fetch, set the upstream, and update origin's HEAD.
The renamed branch still tracks the old upstream. Push with -u once, or run git branch -u origin/new-name, and later pushes and pulls use the new name.
Related: Git cheat sheet, Git rebase guide, Git worktree guide, GitHub personal access tokens.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.