私が歌川です

@utgwkk が書いている

手元のブランチ名リストを出力する

git branch の出力をそのまま使おうとすると、current branchを表すマーカーとpaddingが邪魔になります。

$ git branch
  ...
* master
  ...

sedとか駆使したら消せるんだろうけどgitコマンドだけで完結させられないか、と思ったらformatを指定すればうまくできました。

git branch --format='%(refname:short)'

Stackoverflowに似たような回答がありました。

stackoverflow.com

応用

pecoで絞り込んでswitch

git switch $(git branch --format='%(refname:short)' | peco)

マージ済のブランチをぜんぶ消す

git branch --format='%(refname:short)' | xargs git branch -d

参考