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
  master
* old_branch

$git branch -m old_branch new_branch

$git branch
  master
* new_branch

$git push origin :old_branch 
Password for 'https://user@bitbucket.org':
To https://user@bitbucket.org/user/repository.git
 - [deleted]         old_branch 

$git push origin new_branch
Password for 'https://user@bitbucket.org':
Counting objects: 1, done.
Writing objects: 100% (1/1), 187 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To https://user@bitbucket.org/user/repository.git
 * [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.