概要
git init
したら、下記のようなhint が出てきたので、その場合の対処法を書きます。
(git init でGitリポジトリを初期化した際に、デフォルトで master という名前のブランチが作成されたケース)
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>
Initialized empty Git repository in /Users/hoge/work/Go-Project/Go-Learn/.git/
hoge@hogenoMacBook-Pro Go-Learn % git config
usage: git config [<options>]
解説
git initコマンドを実行したことで、Gitリポジトリが初期化されて、新しいブランチとしてmasterブランチを作成しました。
が、最近のGitでは、master という名前の代わりに main や他の名前を使うことが推奨されており、これに関する警告が表示されているようです。
対処法
Gitの設定を変更すればok。
手順1
グローバル設定を変更する。
git config --global init.defaultBranch <name>
-> ex) git config --global init.defaultBranch main
これにより、今後作成するリポジトリの初期ブランチ名が main になります。
手順2
masterブランチからmainブランチに変更する。
現在のブランチ名の変更: 既に作成されたブランチの名前を変更したい場合は、
git branch -m <name>
-> ex) git branch -m main
以上です!
まとめ
- 新しいリポジトリで使用するデフォルトのブランチ名を変更したい場合は、
git config --global init.defaultBranch <name>
で設定できる。 -
git branch -m <name>
で現在のブランチ名を変更することができる。