How to rename a local and remote branch in git?
Written on by Sahil Bhatacharya in Mistakes Correction
Shit Happens!! There are times where you named a branch wrong or want to make it more meaningful. Doing it locally is quite simple:
git branch -m new-branch-name
In case you are on a different branch, you can do it like this:
git branch -d old-branch-name new-branch-name
Rename git branch on remote
In some cases, you might have pushed your branch to remote too, for that you can run the following command to rename it on remote too:
git push origin :old-branch-name new-branch-name
To reset the upstream branch for the newly named local branch
Switch to the branch and then run the following command:
git push origin -u new-branch-name