$0.21

How do I rename a local Git branch?

Ask a question+
1

How can I rename a local branch which hasn’t been pushed to a remote branch?

add comment

1 Answer

1

If you want to rename a branch while pointed to any branch, do:

git branch -m <oldname> <newname>

If you want to rename the current branch, you can do:

git branch -m <newname>

A way to remember this is -m is for “move” (or mv), which is how you rename files.

If you are on Windows or another case-insensitive filesystem, and there are any capitalization change in the name, you need to use -M, otherwise, git will throw branch already exists error:

git branch -M <newname>

Source: https://www.w3docs.com/snippets/git/how-to-rename-git-local-and-remote-branches.html

add comment

Your Answer