日々精進

新しく学んだことを書き留めていきます

.zshrcに定義するfunctionなどではgit branchでなく、git for-each-refを使う

git for-each-refはbranchの一覧を表示するが、git branchより細かく表示する情報を加工したりできるので
aliasやfunctionでbranchを選択するところではこっちを使った方がよさそう。
例えば、pecoでbranchを選択するglobal aliasは以下のように定義するとコミット日順にソートしてくれるし、コミット日も表示される。

alias -g B='`git for-each-ref --format="%(authordate:short) %(refname)" --sort=-committerdate refs/heads refs/remotes | peco | cut -d" " -f2 | cut -d/ -f3-`'

参考:ブランチ一覧を更新時刻つきで表示したい場合、gitのfor-each-refが使える。 - Bye Bye Moore