Sunday, November 27, 2016

How to rename a remote branch in GIT

There is no functionality to rename a remote branch in GIT. In order to do this, you checkout the remote branch as a new local branch with a new name, push it as a new remote branch, and finally delete the old remote branch.

Here's the cookbook:

1. Checkout the remote branch with a new name:
git branch new-branch-name origin/old-branch-name
2. Push the newly named local branch to remote:
git push origin --set-upstream new-branch-name
3. Delete the old remote branch:
git push origin :old-branch-name