All How-Tos
Beginner

How to Rename a Git Branch

Learn how to rename local and remote branches in your Git repository.

Rename Branch

Renaming a branch in Git involves several steps:

  • Rename the local branch by using either git branch -m <newname> for the current branch, or git branch -m <oldname> <newname> for any non-HEAD branch:
git branch -m <newname>
git branch -m <oldname> <newname>
  • Push the rename and removal using the following command. Note that this might fail due to changes on the remote.
git push <remote> <oldname>:<newname> :<oldname>
  • Reconfigure the tracking branch with:
git branch --set-upstream-to=<newname-remote-name> <newname>