How do I rename a local Git branch? How do I rename a local Git branch? git git

How do I rename a local Git branch?


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>

If you want to push the local branch and reset the upstream branch:

git push origin -u <newname>

And finally if you want to Delete the remote branch:

git push origin --delete <oldname>

A way to remember this is -m is for "move" (or mv), which is how you rename files. Adding an alias could also help. To do so, run the following:

git config --global alias.rename 'branch -m'

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:

git branch -M <newname>


git branch -m old_branch_name new_branch_name

The above command will change your branch name, but you have to be very careful using the renamed branch, because it will still refer to the old upstream branch associated with it, if any.

If you want to push some changes into master after your local branch is renamed into new_branch_name (example name):

git push origin new_branch_name:master (now changes will go to master branch but your local branch name is new_branch_name)

For more details, see "How to rename your local branch name in Git."


To rename your current branch:

git branch -m <newname>