• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Computing / Git Change Default Branch to Main

Git Change Default Branch to Main

Last updated on August 14, 2020 by Sal Ferrarello

In Git 2.28 you can change the default branch name from master to whatever you want (the name main seems to be a popular choice).

Set Your Default Branch Name

If you run the following from the command line

git config --global init.defaultBranch main

it will set the defaultBranch name to main in your global git config file (typically ~/.gitconfig).

Now when you run

git init

in a new directory, it should initialize a Git repo with the branch name main. You can check the branch name with

git status

What if it doesn’t work?

If you are using a version of Git less than 2.28, this setting will have no effect.

You can determine what version of Git you are running by running the following from the command line.

git --version
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Computing, Dev Tips, Draft, Solution Tagged With: Git, gitconfig

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in