git master ブランチを main ブランチに変更する2021年01月11日 12時39分20秒

所持事情により git でブランチ名を変えることがあるのでメモ。git branch の -m オプションに古いブランチ名を渡し、第一引数に新しいブランチ名を渡す。
% git branch
* master
% git branch -m main master
fatal: A branch named 'master' already exists.
% git branch -m master main  
% git branch
* main
逆にしてもエラーが表示されるだけで、実質的な被害は無い。