33.9 Git Branch Rename

20210416

With the change of the default naming of the core branch of a repository to main (by GitHub from 1 October 2020) users can rename their default branch from master to main.

On GitHub GitHub in the browser directly supports a name change. Browse to the branches page and click the edit icon. This will allow the name to be changed. Then for the local clone of the repository:

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

In General Otherwise, the general command line recipe is primarily done on a local clone. The first step is to move (-m or --move) the master branch to the main branch. Then push the new main branch to the repository setting it as the default for our upstream/origin (-u or --set-upstream). Finally point HEAD to the new branch.

git branch -m master main
git push -u origin main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

Then, connect to GitHub, BitBucket, or GitLab and under Settings/Branches or Advanced select main as the default branch.

Next, back to the command line to delete the master branch:

git push origin --delete master

Others who may have the master branch checked out will need to do the following:

git checkout master
git branch -m master main
git fetch
git branch --unset-upstream
git branch -u origin/main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0