git initでUsing 'master'〜と表示される原因
現在はターミナルでgit initを実行すると以下のような黄色のhintが表示されることがある。
$ git init
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>
これはgit configでデフォルトのブランチ名が設定されていないと表示されます。
2020年からGitHubではmasterは人種差別に反対する「Black Lives Matter」運動によりmainを使用することになりました。
GitHub、「マスター」「スレーブ」などの用語を見直し--人種差別撤廃に賛同
そのためGitでも現在はgit configでデフォルトのブランチ名が設定されていない場合はgit initを実行するとヒントが表示されるようになりました。
git initでUsing 'master'〜と表示される場合の対策
もしgit initを実行した際にヒントを表示させたくない場合は以下のコマンドでブランチ名を設定します。
現在はGitHubのデフォルトのブランチ名がmainになっているのでgit configにもmainを設定することを推奨します。
git config --global init.defaultBranch main
デフォルトのブランチ名が設定されているか確認するには「git config --global init.defaultbranch」を実行します。
mainがデフォルトのブランチ名になっている場合は実行後にmainが表示されます。
git config --global init.defaultbranch
init.defaultbranchがmainの状態でgit initを実行すれば黄色のヒントは表示されず、初期ブランチ名がmainになります。