1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

main以外の不要なブランチを一括削除

Posted at

完全僕の備忘録です。
いっぱいリリースしたあと、いっぱいブランチ残っちゃうじゃないですか。
それを一括削除するコマンドです。

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 オプションは、未マージの変更があるブランチでも削除する強制オプションです。

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?