How do I rename a local Git branch?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
You must login to ask question.
If you want to rename a branch while pointed to any branch, do:
If you want to rename the current branch, you can do:
If you want to push the local branch and reset the upstream branch:
And finally if you want to Delete the remote branch:
A way to remember this is
-m
is for “move” (ormv
), which is how you rename files. Adding an alias could also help. To do so, run the following:If you are on Windows or another case-insensitive filesystem, and there are only capitalization changes in the name, you need to use
-M
, otherwise, git will throw branch already exists error: