ONIZU

Renaming a git branch (from server to local)

Apr 13, 2021 / Dushyant Basson

git

Recently got this useful info from GitHub on updating a git branch locally after renaming it on the server.

Assuming the branch's old name was 'main' and it is renamed to 'master', and its local clone exists, execute the following on local terminal:

git branch -m main master
git fetch origin
git branch -u origin/master master
git remote set-head origin -a

That should successfully complete the renaming of the branch (at the local end).