1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Git,GitHub】デフォルトブランチ名を変更する方法

Last updated at Posted at 2021-03-19

はじめに

2020年10月にmasterが差別用語にあたる可能性があるためGitHubのデフォルトブランチがmasterからmainに変更されました。その経緯についての深堀りはここではしません。知りたい方はこちらのURLがわかりやすかったです。

問題点

リモートブランチとしてGitHubを用いる場合デフォルトはmainですが、Git(ローカルブランチ)のデフォルトはmasterのままです。このままでは祖先のブランチ名が異なるためGitHubにpushできません。
一度だけならブランチ名を変更して対応してもいいですが、毎回ブランチ名を変更するのは面倒ですよね、そこで、デフォルトブランチ名を変更して自動で生成されるブランチ名を変更しましょう。
対応としては、Gitのデフォルトブランチを変更するかGitHubのデフォルトブランチを変更するか2種類ですね。その両方の方法について記述してみました!

変更方法

1. Gitのデフォルトブランチをmaster→mainに変更する

git config --global init.defaultBranch main

以後、git initした時にmainブランチが生成されます

設定が反映されたか確認する方法(知りたい人だけ見てください)方法は色々あると思いますがここでは2つ紹介します 1つ目 `$ git config --list` を実行して init.defaultbranch=main になっていればOK 2つ目 /home/.gitconfig ファイルを開く(homeはホームディレクトリ、.gitconfigファイルは隠しファイルです) `[init] defaultBranch = main` になってればOK

2. GitHubのデフォルトブランチをmain→masterに変更する

下記のリンクをクリックした後、mainからmasterに変更してUpdateしてください
https://github.com/settings/repositories

さいごに

mainを使うのかmasterを使うのか、developなどのそれ以外の名前を使うのかは会社やチーム事に違うと思いますが、上記の方法で変更できますね。以上です!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?