git branchコマンドで現在のブランチ名を表示する方法
git branchコマンドで現在のブランチ名を表示するには--show-currentオプションを指定します。
オプションの説明
--show-current Print the name of the current branch. In detached HEAD state, nothing is printed.
--show-currentオプションを指定した場合
$ mkdir codebase $ cd codebase $ git init -b main Initialized empty Git repository in /home/testuser/codebase/.git/ $ git branch --show-current main