Read in 1 minutes
How To Rename a Local and Remote Git Branch
You are collaborating on a project with a group of people and you have defined a naming convention for git branches. You created a new branch, pushed the changes to the remote repository and realized that your branch name was incorrect.
Luckily, Git allows you to rename the branch very easily using the
This guide will explain how to rename local and remote Git branch.
Renaming Git Branch
Follow the steps below to rename a Local and Remote Git Branch:
Start by switching to the local branch which you want to rename:
git checkout <old_name>
Rename the local branch by typing:
git branch -m <new_name>
If you’ve already pushed the
<old_name>branch to the remote repository delete the
git push origin --delete <old_name>
Finally push the
<new_name>local branch and reset the upstream branch
git push origin -u <new_name>
That’s it. At this point you have successfully renamed your local and remote Git branch.
Renaming a local Git Branch is just a matter of one command. However you can’t directly rename a remote branch, you need to delete it and then re-push the renamed local branch.
If you hit a problem or have a feedback, leave a comment below.