simple-web-system technology

Webに関する技術をシンプルに扱うブログ

gitで最近使ったbranchにswitchする

gitで最近使ったブランチに移動したい時がある。

git switch -だと1個前のブランチに戻れるが、2,3個前に移動したブランチに移動するのは面倒

# ブランチの最新のコミット日時で降順ソート。"commitdate"で昇順、 "-commitdate"で降順
git branch --sort=-committerdate

# ブランチをコミット日時が新しい順に並べて、fzfで選択して移動する
git branch --sort=-committerdate | fzf | xargs -I{} git switch {}