GitHub recently changed the default branch name of new repositories from master to main, which is great for inclusivity. But I haven't seen anybody mention how to change the default branch name used by the git init command.

Changing it manually

You can pass the -b flag to the git init command to manually change the default branch name:

git init -b main

This is OK, but it's a bit of a pain to do this manually for every new repository. It would be nicer if we could just run git init and have the default branch name be main instead of master.

Changing it automatically

As of git 2.28, it's possible to set the default branch name used by the git init command:

git config --global init.defaultBranch main

Now when you run git init, the default branch name will be main instead of master.

You can run git --version to check which version of git you're on. If you're on a version below 2.28, you'll need to update for this to work.