How to Rename a Git Branch

If you want to rename a git branch, then you have a few options, dependent on the use-case.

Option 1 – Rename a Git Branch

git branch -a <oldname> <newname>
Code language: Bash (bash)

Option 2 – Rename the Current Branch

git branch -m <newname>
Code language: Bash (bash)

Option 3 – On Windows

Windows required a capital “-M” instead.

git branch -M <newname>
Code language: Bash (bash)

Push the Local Branch and Reset the Upstream Branch

git push origin -u <newname>
Code language: Bash (bash)

Delete the Old Remote Branch

git push origin --delete <oldname>
Code language: Bash (bash)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments