How To Rename a Local and Remote Branch in Git

You’re working with a team of developers and have all agreed to a naming convention with your branch names, but you accidently pushed the wrong branch name upstream.

You could delete the whole thing and start again, but the easiest way is to use git commands to rename the branch for local and remote.

This quick guide will show you how to rename local and remote Git branches.

Rename a branch locally

Switch to the branch you want to rename (unless you’re already on the branch)

git checkout oldbranchname

Rename the branch locally.

git branch -m newbranchname

Now you have renamed the local branch but the remote branch still has the old name. The quickest way to correct this is to push your newly named branch upstream then delete the old remote branch.

git push origin -u newbranchname
git push origin --delete oldbranchname

You have successfully renamed the local and remote Git branch.