完全僕の備忘録です。
いっぱいリリースしたあと、いっぱいブランチ残っちゃうじゃないですか。
それを一括削除するコマンドです。
git checkout main && git branch | grep -v "main" | xargs git branch -D
解説
git checkout main
現在のブランチを main に切り替えます。
git branch | grep -v "main"
git branch の出力結果から main ブランチを除外します。grep -v は指定された文字列(ここでは main)を含む行を除外するコマンドです。
xargs git branch -D
最後に、xargs を使って、git branch -D コマンドに残りのすべてのブランチを渡します。
git branch -D はブランチを強制的に削除するコマンドです。-D オプションは、未マージの変更があるブランチでも削除する強制オプションです。