My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping


Friday, March 24, 2017

Git : Rename / Change Branch name : How to Change the branch name of a local or a remote branch in git

There are multiple scenarios if you want to change the name of the branch. Sometimes you could have named a branch incorrectly, and sometimes it could be because you didn't follow the naming guidelines as per your team and organisation. Whatever be the cause, you very well need to know the method to do so.

The process is as follows:

1. First, rename your local branch.  (Sometimes you need to only do this. For example if the branch is yet not pushed on stash.)
If you are on the branch you want to rename:
Syntax: git branch -m new-name

2. In case you are on a different branch:
Syntax: git branch -m old-name new-name

3. Now suppose you want o delete the old remote branch and push the new-name local branch.
Syntax: git push origin :old-name new-name

Or, 4. You can also reset the upstream branch with the new branch local branch.
For this you need to switch to your new local branch and then:
Syntax: git push origin -u new-name

No comments:

Post a Comment