Git:ブランチ名をmasterではなくmainで作成する方法

スポンサーリンク

ブランチ名をmasterではなくmainで作成する方法

ブランチ名をmasterではなくmainで作成するにはinit.defaultBranch設定または--initial-branchオプションを使用します。

 

$ git init  # デフォルトがmasterになっている場合
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 
Initialized empty Git repository in /home/testuser/testdir/.git/
$ git branch --show-current  # masterで作成される
master

$ git config --global init.defaultBranch main  # init.defaultBranchにmainを設定する
$ git init
Initialized empty Git repository in /home/testuser/testdir/.git/
$ git branch --show-current  # mainで作成される
main

$ git init --initial-branch main  # または--initial-branchオプションでmainを指定する
Initialized empty Git repository in /home/testuser/testdir/.git/
$ git branch --show-current  # mainで作成される
main
Git:ブランチ名をmasterからmainに変更する方法
ブランチ名をmasterからmainに変更する方法 masterで作成した後でブランチ名をmainに変更するには以下のようにします。 $ git branch -a # ブランチ名の確認 * master remotes/origin/ma...