Pages

Thursday, August 7, 2014

Change the name of remote git branch

Warning: Reader is strongly encouraged to take a backup of the local repository before performing the steps mentioned in this post.

This post is intended to guide the reader about how to change the name of a remote branch in Github. Suppose there is a branch named feature/branch_a, and it is to be renamed to test/branch_a. The initial remote and local repositories may look something like this:

Remote:

enter image description here

Local:

enter image description here
* Command(s):
-  git branch -v (Shows a list of all branches, with current branch highlighted)

With the branch feature/branch_a checked out, create a new branch with the name test/branch_a.

enter image description here
* Command(s):
-  git branch -v (Shows a list of all branches, with current branch highlighted)
-  git checkout -b test/branch_a (Creates a new branch and at the same time switches to the branch)

Push the branch on the remote server, and then delete the older branch from both remote and local repositories.

enter image description here
* Command(s):
-  git push --set-upstream origin test/branch_a (link locally create branch to the remote server, and push it)
-  git push origin :feature/branch_a test/branch_a (Deletes branch from remote and replaces it with the new one)

That is it! You are good to go.

enter image description here

Enjoy!