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

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

Free Alternatives to GitHub for Private Git Hosting

GitHub is super awesome, until you have to start paying for it. Check out two feature-full and FREE alternatives.

Jan 08, 2015

Git Merge: Accept All Changes

Have you encountered a large merge when you know you are going to accept all current or incoming changes? There's a way to achieve without stepping through each file.

Sep 17, 2020