LoginSignup
58

More than 5 years have passed since last update.

git show-branch を使っていないだなんて!

Posted at

「オレは git の alias こんな風にしてるぜ!」っていう投稿とかブログ記事、よく見かけるし実際かなりお世話になっている(ありがとうございます)。…のだが。

誰も git show-branch のエイリアスを設定していなくて信じられない。そんな Git 歴 3 ヶ月の私が通りますよ。

[alias]
    sb = show-branch
$ git sb
* [master] Add 'git show-branch'.
 ! [fixes] Introduce "reset type" flag to "git reset"
  ! [mhf] Allow "+remote:local" refspec to cause --force when fetching.
---
  + [mhf] Allow "+remote:local" refspec to cause --force when fetching.
  + [mhf~1] Use git-octopus when pulling more than one heads.
 +  [fixes] Introduce "reset type" flag to "git reset"
  + [mhf~2] "git fetch --force".
  + [mhf~3] Use .git/remote/origin, not .git/branches/origin.
  + [mhf~4] Make "git pull" and "git fetch" default to origin
  + [mhf~5] Infamous 'octopus merge'
  + [mhf~6] Retire git-parse-remote.
  + [mhf~7] Multi-head fetch.
  + [mhf~8] Start adding the $GIT_DIR/remotes/ support.
*++ [master] Add 'git show-branch'.

(man git show-branch の実行例から抜粋)

ちゃんと色つける設定にしてれば左側のマークが色分けされる。* が current branch で、! はそれ以外の HEAD、- はマージ、+ が普通のコミットを表している。

オプションは --all--more をよく使う。自分の場合、remote branch との比較でよく使うから、alias で常に --all をつけている。

$ git sb --all
(remote-tracking branch も表示)
$ git sb --more=5
(もっとたくさん表示)

いわゆる git graph 系と比べて、ブランチ間の進捗状況の差を確認するのに向いていると思う。git rebase する前に必ず叩いてる。あと diverge したって怒られた時とか。


余談。ついでに、「確認する」系のコマンドを片っ端から一まとめにした git cfm っていう alias も作ってある。.zshrc に .git のあるディレクトリに移動した時に自動で git cfm する設定書いてあるから、実際にはそんなに頻繁に叩いていないけど、色々と作業内容とか忘れがちなので重宝している。

[alias]
    sb = show-branch -a
    br = branch
    st = !git status -s && git stash list | cat
    cfm = !git sb && git br && git st

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
58