All commands
# Step 1
# create main branch locally, taking the history from master
git branch -m master main
# Step 2
# remove the "upstream" branch link to origin/master
git branch --unset-upstream
# Step 3
# push the new local main branch to the remote repo (GitHub)
git push -u origin main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
# Step 4
# change the default branch on GitHub to main
# https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch
# retarget existing PRs
# https://github.com/ethomson/retarget_prs
# Step 5
# delete the master branch on the remote
git push origin :master
Easily rename your Git default branch from master to main by Scott Hanselman
Git: Renaming the “master” branch by Richard Walters
How To: Safely Rename master Branch on GitHub by Jake Jarvis