Barcelona Code School

Changing default git branch to main

As you might have noticed lately when initialising a new git project with git init you might see this warning in the terminal:

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>

This is due to git project, same as GitHub and GitLab, changing the default branch name from master to main due to ‘master’, is offensive to some people and we empathize with those hurt by the use of that term., link

So the main branch is not master anymore.

So there is a discrepancy arising from the git initializing the project with a branch master but GitLab/GitHub creating a new repo with default branch main and we can not push without some tweaks.

To avoid conflicts and errors we suggest to set your global config for Git to initialize all new projects with a branch main by running this int he terminal once:

git config --global init.defaultBranch main

On Mac if you have complaints about access right add sudo before this command

In this way you will be up to date with this change and all the new git projects initialized with git init will have default branch main in consistence with GitLab/GitHub.

Thanks!

Back to posts