Riccardo Coppola

git: rename a branch [locally and remotely]

January 29, 2016

It happens to me quite a lot: I create a branch and then want to rename it to a more specific/correct name.
If that branch has already been pushed to a remote, this operation is a bit trickier than the usual renaming.

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

Enjoy!


Notes on web development, life, learning and the world.