0
0

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 1 year has passed since last update.

【Git】カレントブランチ名を取得する方法

Posted at

以下のコマンドでカレントブランチ名を取得できます。

git rev-parse

ターミナル
$ git rev-parse --abbrev-ref HEAD
main

$ git rev-parse --abbrev-ref @
main

detached HEADの場合にはHEADと出力される。

git symbolic-ref

ターミナル
$ git symbolic-ref --short HEAD
main

detached HEADの場合にはfatal: ref HEAD is not a symbolic refと表示され異常終了する(終了コード: 128)。

git branch

ターミナル
$ git branch --show-current
main

detached HEADの場合には何も出力されず正常終了する。

git name-rev

ターミナル
$ git name-rev --name-only HEAD
main

$ git name-rev --name-only @   
main

detached HEADの場合にもブランチを取得できる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?