Suppress git warning about default initial branch name

Viewed 2529

When creating a new Git repo you now see this message:

Initialized empty Git repository in /private/var/folders/g5/8twmk1xj481_6btvppyw5j4h0000gp/T/.tmpNYVg6H/.git/
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>

Is there a way to suppress this message without changing my global git config?

2 Answers

It seems like you can do

git init --quiet   # or git init -q

I'm not exactly sure what other information that will suppress but it suppresses this notice.

However it does mean that the initial branch name is not well defined (they might change it to e.g. main later), so it's probably best to do this:

git init --initial-branch=master    # or git init -b master

This will suppress the initial branch warning message for the current user:

git config --global init.defaultBranch master

This will suppress it system-wide:

sudo git config --system init.defaultbranch master

Credit to comments by Timmmm & jonrsharpe

Related