HOWTO to rename GIT branch

To rename a GIT branch, we must follow two separate steps.

Rename the local branch

Switch to the branch we need to rename, and then type the command below:

git branch -m <new branch name>

Rename the remote branch

This step is necessary only if the old branch already exists in the remote repository.

  • push the branch with the new name:
git push -u <git_repo> <new branch name>
  • and then delete the old one.
git push -u <git_repo> --delete <old branch name>