Renaming master to main on GitHub
The idea of renaming the master branch scared the git out of me, but it’s easy and quick.
You will need to rename the remote branch and all local branches that target it.
Changing the Name of the Remote Repository
Step 1: Open your Branches Settings
In your browser, on your GitHub repository page, open your Branch Settings:
Click the pencil icon, enter “main” in the textbox, and click the Rename branch button:
That’s it for GitHub.
Renaming the Local master Branch
The next time any developers visit the repository on GitHub, they will be presented with this screen:
Those commands are:
git branch -m master main git fetch origin git branch -u origin/main main git remote set-head origin -a
Here‘s the result of running those at the terminal:
> git branch -m master main > git fetch origin > git branch -u origin/main main Branch 'main' set up to track remote branch 'main' from 'origin'. > git remote set-head origin -a origin/HEAD set to main
And let’s do a
git status just to be sure:
> git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
All set. Easy peasy. Have no fear. Make the change.