1 min read

Set your default branch to `main` with .gitconfig

All GitHub repositories starts to switch from master to main from 1 October 2020. Despite the change, it is not enforced that the master branch will face with any significant problems if anyone continues to use. However, new repository created will use the main branch as the default.

Since most new projects will now start with the main branch as the default, we would like to reduce the need to re-configure between master and main.

How to change to use main as the default branch

Luckily, git allows us to do this quickly and easily from the global configuration.

There are two ways we can do so.

  1. We can edit the ~/.gitconfig file directly with the following changes.

defaultBranch = main

  1. Using the CLI command to set the configuration

git config --global init.defaultBranch main

With the new configuration, we will now be able to create git repositories with the branch being created as main right from the onset.

Of course, certain organisations may use very different naming for their default branch and we can use the same way to make the changes accordingly.