How To Rename A Remote Branch in Git

In order to rename the remote branch we need to rename it locally, to remove the old name of branch from remote repository and then to push the branch renamed with the new name to the remote repository:

1. Switch to the branch you want to rename, then rename it it locally:

git checkout old_branch
git branch -m old_branch new_branch

2. Remove old branch from remote repository:

git push origin :old_branch

3. Push the renamed local branch to remote repository:

git push origin new_branch

Full Console:

$git checkout old_branch 
    Switched to branch 'old_branch'

$git branch
* old_branch

$git branch -m old_branch new_branch

$git branch
* new_branch

$git push origin :old_branch 
Password for '':
 - [deleted]         old_branch 

$git push origin new_branch
Password for '':
Counting objects: 1, done.
Writing objects: 100% (1/1), 187 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
 * [new branch]      new_branch -> new_branch

Did you enjoy this tutorial? Be sure to subscribe to the my RSS feed not to miss my new posts!
... or make it popular on

Leave a Comment.