Gitの初期ブランチ名に関するGitメッセージを無効にする方法 質問する

Gitの初期ブランチ名に関するGitメッセージを無効にする方法 質問する

Microsoft が最近 github リポジトリの初期ブランチ名を変更したことは理解していますが、今、自分のコンピューターで「git init」を実行すると、初期ブランチ名を「master」など他の名前に変更できることを説明する黄色の警告メッセージが表示されます。黄色のメッセージを見ると、注意を引くのでデフォルトで読んでしまうため、気が散ってしまい、不安になり、安心して作業できません。

では、そのメッセージを無効にするにはどうすればよいでしょうか?

正直言って、ブランチ名のデフォルト設定を変更するのはちょっとばかげているので、変更するつもりはまったくありません。

ベストアンサー1

新しいバージョンの Git では、新しいリポジトリを初期化するときに警告が表示されます。

$ git init
warning: templates not found in /home/ja/share/git-core/templates
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>
Initialized empty Git repository in /tmp/new/.git/

では、そのメッセージを無効にするにはどうすればよいでしょうか?

そこにはこう書いてあります。

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>

したがって、マスターを使い続けたい場合は、次のようにします。

git config --global init.defaultBranch master

ちなみに、

Microsoftは最近、githubリポジトリの最初のブランチ名を変更したと理解しています

Microsoft は大きくて強力ですが、Git を所有しているわけではありません。

おすすめ記事