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

Delete Multiple Local Git Branches

Learn how to use a single command to delete multiple git branches.

Jun 21, 2021

Git Checkout Previous Branch

Checkout the previous git branch without needing to remember or type the name.

Jul 27, 2022