Created by sirideLinked to 93.1m issues across 231 teams
Here's how to rename a local Git branch:
First, you need to rename the current branch:
git branch -m <newname>
The -m
flag is short for --move
.
If you want to rename a branch while pointing to any branch, use the following command:
git branch -m <oldname> <newname>
Once you have renamed the branch, you need to push the new name to the remote branch and reset the upstream branch:
git push origin -u <newname>
Finally, you need to delete the old remote branch:
git push origin --delete <oldname>
If you are using Windows or another case-insensitive filesystem, use -M
if there are only capitalization changes in the name. Otherwise, Git will throw a "branch already exists" error.
git branch -M <newname>
You can also create an alias for git rename
:
git config --global alias.rename 'branch -m'
Contributor
Teams
231