How to rename a Git branch

Last updated on 02/02/2018

Supposedly you have misspelt your branch name "my_nise_branch" and you want to rename it to "my_nice_branch".

Here is how you change it.

 

Rename the branch locally

git branch -m my_nise_branch my_nice_branch

In case your branch is already pushed remotely you should delete and push the new branch remotely

Delete the old branch

git push origin :my_nise_branch

Push the new branch to remote and track it

git push --set-upstream origin my_nice_branch