1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Git】毎回masterからmainに変更するのが面倒くさいので、init時のデフォルトブランチ名を変更してみた

Last updated at Posted at 2025-08-11

はじめに

Gitではgit initをすると、デフォルトブランチがmasterになります。
しかし、最近ではGitHubをはじめ、初期ブランチ名をmainに統一する流れになっています。

この流れに沿う場合、ローカルでリポジトリを作る時はmasterからmainに手動で変更する必要があります。

git branch -m master main

しかし、毎回手動で変更するのは面倒なので、
初期化時のデフォルトブランチ名を最初からmainにしようと思います。

設定方法

1. 現在のGitバージョンを確認

この機能はGit 2.28(2020年7月リリース)以降で利用可能です。

git --version

2. デフォルトブランチ名を変更する

git config --global init.defaultBranch main

--globalを付けることで、すべての新規リポジトリに適用されます。
ユーザー単位で設定するため、1回設定すれば以降は不要です。

以下のコマンドで設定内容を確認できます

git config --global --get init.defaultBranch

3. git initを実行する

UserName MINGW64 ~/SampleGit
$ git init
Initialized empty Git repository in C:/Users/userName/SampleGit/.git/

UserName MINGW64 ~/SampleGit (main)

git init実行後に(main)が表示されていることが確認出来ました。
以上で設定完了となります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?