Stock photo by Yancy Min
👋 Hi, all! Best practices have changed! We're using
main for our primary git branch now, because racism sucks, including terms that come from slavery like
master. Here's how to update with minimal disruption to your workflow in three(ish) simple steps.*
- Use an up-to-date version of Git.
- Add a line to your
- Change the default in GitHub.
1. Use an up-to-date version of Git
If the version that comes with your distro is ≥ 2.28, you're in good shape. Otherwise, head to git-scm.com/download/linux and install a newer version.
Or you can install it with Homebrew (yes, that Homebrew ⬇️) and get an up-to-date version by default. More on that in another post.
The version that Xcode installs is too old. That's ok though.
Since you probably have Homebrew installed already, you can simply...
brew install git
...to get up to date.
This version will be prioritized in your PATH over the old version, and your existing .gitconfig file will work just fine.
If the former, just...
choco upgrade git
...and you should be golden.
If the latter - head back there and get yourself a newer copy.
2. Add a line to your
You can run this command to change the default branch to
main for all new repos created on your local machine:
git config --global init.defaultBranch main
This appends the following lines to your
[init] defaultBranch = main
3. Change the default on GitHub
You don't actually have to do anthing - they've already done it!
New repos automatically get created with
main as the default branch. But if you'd like to change it to something cheeky like
trunk, you can do so by going to
*The messy bits
- Unfortunately, at the time of this writing, neither GitLab nor Gitea support globally changing the default branch for new repos. However, you can change this on a per-repo basis in the project settings.
- Don't forget to change the "build from" branch in any pipelines you've created or they'll break.
Is there anything special about
Nope! It's just been the historical default for a lot of things. But in the eyes of Git, a branch is a branch. The name is just another string.
Why are you FORCING me to CHANGE!? RAWR!!
I'm not. I can't force you to do anything. However...if your reasons for maintaing maintain the status quo are anything other than compatibility of legacy software...you should really reconsider whether they're good reasons.