【Git】デフォルトブランチをmasterからmainに変更するコマンド

ちょっと前にmasterは人種差別を連想させるからデフォルトブランチはmasterではなくmainにしよう!みたいな動きがあったと思いますが、デフォルトブランチはmasterのまま使っておりまして毎回mainに手動で変更しておりました。

が、流石にめんどくさくなってきたので設定で変更しました。
git initした時も以下のようなhintが表示されていました。


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 
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 

デフォルトブランチをmainにする


git config --global init.defaultBranch main

現在のブランチ名をmainにする


git branch -M main