Nov 2, 2022 1 min read

How do I rename a local Git branch?

To rename the current branch:

git branch -m <newname>

To rename a branch while pointed to any branch:

git branch -m <oldname> <newname>

-m is short for --move.


To push the local branch and reset the upstream branch:

git push origin -u <newname>

To delete the remote branch:

git push origin --delete <oldname>

To create a git rename alias:

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

On 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>
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to BugFix.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.