wada811 / blog

wada811's blog
https://github.com/wada811/blog/issues
Apache License 2.0
6 stars 0 forks source link

git branch --format=FORMAT でブランチ名のリストを出力する #34

Open wada811 opened 5 years ago

wada811 commented 5 years ago

Why

Git のブランチ名のリストが欲しい。

What

  1. git branch | tr -d '*' | tr -d ' '
  2. git branch --format=<format>

How

1. git branch | tr -d '*' | tr -d ' '

単純に git branch すると以下のようになる。

* develop
  master

そのため tr* と半角スペースを除去する。

2. git branch --format="%(refname:short)"

develop
master

1 と 2 の違い

-a オプションを付けたときの結果が異なる。

1. git branch -a | tr -d '*' | tr -d ' '

develop
master
remotes/origin/master

2. git branch -a --format="%(refname:short)

develop
master
origin/master

Ref