Rename master branch to main in GitHub

Updated: September 16, 2022
Tags:git

First, make sure to change the name of the branch on GitHub:

Go to your GitHub repository
https://github.com/:username/:repo-name/branches

Then, change the name of the branch locally:

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