LoginSignup
1
1

More than 3 years have passed since last update.

ローカルブランチをコマンド一発で削除する

Last updated at Posted at 2019-08-06

ブランチの一括削除

ローカルのブランチが増えすぎた時、コマンド一発で一旦消して綺麗にしたくなる。
その時のコマンド

git branch | xargs git branch -D

コマンドの内訳

git branchでブランチ一覧の取得

git branch

ブランチ名を引数にブランチの削除を実行

git branch -D <branch_name>

でブランチの削除が行える。
パイプとxargsを用いて、git branchで取得したブランチ名を引数に削除を実行する。

削除するブランチを絞り込みたい時

間にgrepを挟めば良い。
例えばfeatureブランチのみを削除したい時

git branch | grep feature | xargs git branch -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