Wednesday, April 6, 2016

Rename a Local Branch in Git

From time to time I have typos crept in the names of Git branches I create. Certainly it is possible to delete a branch and create a new one with corrected name. However Git allows for combining two steps into a single one. Here is a simple way to rename a local branch:
git branch -m <old-branch-name> <new-branch-name>
If a branch which should be renamed is the current one then the command above can be further simplified to the following:
git branch -m <new-branch-name>
If a branch named <new-branch-name> already exists -M option (which is actually just a shortcut for -m -f) can be used to force rename:
git branch -M <old-branch-name> <new-branch-name>
Type in the following command to get more information:
git help branch

No comments:

Post a Comment