How to Rename a Local and Remote Git Branch?

Steps to rename both local and remote git branch

If you're already on the branch (on your local) that you want to rename (along with its corresponding remote branch), then you can do the following:

# rename the branch
git branch -m new-name

# delete the old remote branch and push the new local branch
git push origin :old-name new-name

# switch to the new branch
git checkout new-name

# reset the upstream for the new local branch
git push origin -u new-name

If you're not already on the branch you wish to rename, then you just need to add the local branch name to the first command like so:

git branch -m old-name new-name

Rest of the commands should work in either case.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.