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

  1. Rename the current branch:
git branch -m new-branch-name
  1. Rename another branch:
git branch -m old-name new-name
  1. 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/, or hotfix/.
  • 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.