Rename git branch locally and remotely

  Uncategorized

In case you have created a branch with a wrong name and pushed your branch to the remote git repository you can follow these steps to change the name of your branch.

git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push –set-upstream origin new_branch # Push the new branch, set local branch to track the new remote

Please note, if you use the name of the branch somewhere in your build scripts or somewhere else like SonarQube you have to change it there also.