Home

Git: Set Default Branch to "main" on "init"

Tired of remembering to rename the master branch after running git init? This option will help you!

Okay, so we're starting to standardize on main as the default branch. Super!

My gut says Git will update to some other default branch sometime soon or make you choose. But, for the time being, the default is still master.

You may seen the solution that you can run this command on an existing repo to rename master to main.

$ git branch -m main

That's all well and good and not that painful, but it's still another thing to remember when starting a new project.

But, now Git has a newer config option available in which you can set the default branch on the init command for your machine:

$ git config --global init.defaultBranch main
note

You need to be on a newer version of Git for this to work. See here for determining if you have the option available. If you don't and the command doesn't work for you, you likely have to upgrade Git. Here's a nice guide on how to do that on Mac.

And now every time you run git init, the branch Git will provide you will be main!

Let's Connect

Keep Reading

Git: List All Config Options

See all the options available to you, and also learn how to filter them.

Mar 17, 2021

Collaborate On A GitHub Gist

GitHub gists are designed to be user-specific and not for team collaboration. But you can make it work with a little finagling.

Apr 25, 2018

Safely Force Pushing in Git

If force-pushing is part of your git workflow, here's a tip that can help you avoid disaster.

Jul 22, 2021