Want to help the fight against COVID-19? Take part in this virtual quiz night fundraiser on April 25th, 5pm EST.

Set Default Git Branch Names for New Repositories

July 28, 2020

In a previous post I talked about updating git repositories to use main instead of master: renaming git master branch to use main.

Since then, the folks who help manage git released version 2.28 which allows you to set your own default git repository name, which means you no longer have to use master by default anymore.

It’s worth noting that this currently only works for new repositories that are created locally with the git init command. If you’re using an existing repo, your default branch name will be whatever was previously set.

Update Your Git Version

The easiest way to update git is likely through their website. Download a version and make sure it’s 2.28 or above.

If you’re using mac and have homebrew, you can also run brew update && brew upgrade

Set Your Default Branch Name

A simple 1 liner - run this in your command line and change <defaultBranchName> to whatever you’d like your default branches to be called. One example is main.

git config --global init.defaultBranch <defaultBranchName>

Voila! One less thing to worry about!