How to Rename a Git Branch (Local and Remote)
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.
Full rename, start to finish
Rename a pushed branch everywhere
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-nameWhat teammates run after a rename on GitHub
These 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
What GitHub updates when you rename there
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.
Avoiding names that break later
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.
How it works
- Enter the old name, the new name and the remote, usually origin.
- Tick whether you are on that branch and whether it already exists on the remote.
- Run the commands in order; the builder adds the push, the delete and the upstream fix only when they apply.
- Send the teammate block to anyone else with a clone.
Tips
- Push the new name before deleting the old one, so an open pull request or a CI run never sees the branch vanish completely.
- On GitHub, renaming from the branches page is better for shared branches: it retargets open pull requests and redirects old URLs for you.
- Search your CI workflows, deploy settings and scripts for the old name. GitHub notes that Actions workflows referencing it are not updated.
- git branch -m also renames the branch's reflog, so its local history of moves follows the new name.
Frequently asked questions
Can I rename a remote branch directly?
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.
What is the difference between -m and -M?
-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.
How do I rename master to main on GitHub?
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.
Why does git push still go to the old branch name?
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.
More in Guides
- Git Worktree: Several Branches Checked Out at Once
- GitHub Personal Access Tokens for Git
- GitHub Webhooks: Create, Verify and Redeliver
- GitLab Webhooks: Setup, Verification and Failures
- Google Ads Conversion Tracking
- Google Ads Landing Page Experience
- Google Business Profile Not Showing on Google? Common Causes | How-to Guide
- Google Business Profile Photo Sizes, and a Checker for Your Image
- Git rebase vs merge explained
- Git cheat sheet by task
- GitHub personal access token guide
- Git worktree commands with examples
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App