GitHub is making a major change to the default branch name. As of October 1st, the default branch will be called main
instead of master
. While this is done just for the new repositories and the official recommendation is to wait until the end of year for the existing ones, I was never the one to follow the rules.
To locally change the name of the branch, you just need to move it.
Terminalgit branch -m master main
Next step is telling GitHub you have a new branch:
Terminalgit push -u origin main
If you go to GitHub now, youl'll see both main
and master
present with master
still being the default. To change this you'll need to go into the repository settings and switch default branch there.
Only once that step is done, you can delete master
branch forever.
Terminalgit push origin --delete master
Now the existing repository now has main
as the default branch name.
As you can see, currently this process is a bit involved and I am sure that GitHub will automate it reasonably soon. You might want to wait with local renames until they do. My plan is to update branch names as I push updates to my projects. Active repositories will get the update sooner while some old repositories might stay with master
forever.
That's all fine and dandy but what about the new repositories? Well, there's a setting for that too. Just adjust init.defaultBranch
Git property.
Terminalgit config --global init.defaultBranch main
And now you're ready to roll.
PS: I will not get into politics whether this change was necessary or not. As a Croat, I will never fully understand the slavery and the emotional impact having the master
branch might have. For me this change is more of pragmatism. The exact name doesn't matter much to me and main
is a better choice anyhow.