How to rename a branch in Git
· Category: Git
Short answer
Use git branch -m <old-name> <new-name> or git branch -m <new-name> if on the branch you want to rename.
Steps
- Rename the current branch:
git branch -m new-branch-name
- Rename another branch:
git branch -m old-name new-name
- Update the remote:
git push origin --delete old-name
git push origin -u new-name
Tips
- Inform your team when renaming shared branches.
- Use consistent prefixes like
feature/,bugfix/, orhotfix/. - Update any pull requests or CI configurations referencing the old name.
Common issues
- Other developers may have the old branch checked out; ask them to update.
- Renaming without updating the remote creates a new orphan branch on push.