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>

Option 2 – Rename the Current Branch

git branch -m <newname>

Option 3 – On Windows

Windows required a capital “-M” instead.

git branch -M <newname>

Push the Local Branch and Reset the Upstream Branch

git push origin -u <newname>

Delete the Old Remote Branch

git push origin --delete <oldname>