Switching from 'master' to 'main' in Git Repositories
All GitHub repositories starts to switch from
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
Luckily, git allows us to do this quickly and easily from the global configuration.
There are two ways we can do so.
- We can edit the
~/.gitconfigfile directly with the following changes.
defaultBranch = main
- 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.