1
2

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 initして警告が出た時の対処]Using 'master' as the name for the initial branch. This default branch name

Posted at

概要

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 や他の名前を使うことが推奨されており、これに関する警告が表示されているようです。

image.png

対処法

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> で現在のブランチ名を変更することができる。
1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?