How to Rename a Branch Locally and Remote in Git
This took some googling, so I thought I would document my findings here.
If you’re already on the branch you’d like to rename, just run:
git branch -m new-name
If you’re on say
master, and you have a branch you want to rename now but no
git branch -m old-name new-name
Now that you’ve taken care of your local branch, there’s the unfinished business of mending your remote branch with renaming.
If you use Github or Gitlab (or whatever) you’re going to want to remove the
old-name branch and push the
git push origin :old-name new-name
And finally, push to reset the upstream branch so your local and remote branches are up-to-date:
git push origin -u new-name
Comments, discussion & feedback.
Was this post helpful? Does it need work? Let me know below.