Git:git initコマンドでブランチ名を指定して作成する方法

スポンサーリンク

git initコマンドでブランチ名を指定して作成する方法

git initコマンドでブランチ名を指定して作成するには-bオプションを指定します。

 

オプションの説明

 -b <branch-name>, --initial-branch=<branch-name>
     Use the specified name for the initial branch in the newly created repository. If not specified, fall back to the default name (currently master, but
     this is subject to change in the future; the name can be customized via the init.defaultBranch configuration variable).

 

-bオプションを指定した場合

$ mkdir codebase
$ cd codebase
$ git init -b main
Initialized empty Git repository in /home/testuser/codebase/.git/
$ git branch --show-current
main

 

-bオプションを指定しない場合

$ mkdir codebase
$ cd codebase
$ 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 /home/testuser/codebase/.git/
$ git branch --show-current
master