LoginSignup
1
0

More than 5 years have passed since last update.

[Git] 特定のローカルブランチをまとめて削除

Posted at

Gitは最近は基本的にGUIツールのSourceTreeを使っているが、ブランチをまとめて削除するのが面倒なためコマンドでなんとかする。

対応方法

基本的には git branch で取得したブランチをgrepで絞り込んで、xargs git branch -d を使えば良い

基本1
$ git branch | grep branchname | xargs git branch -d
$ git branch | grep -E regex | xargs git branch -d

git branch -d branchname1 branchname2 と並べて実行できるのでコマンド置換を使っても良い

基本2
$ git branch -d `git branch | grep branchname`
$ git branch -d $(git branch | grep branchname)

個人的にはxargsのほうが対象の絞込を確認してから、後ろにつなげればそのまま実行できるので、前者のやりかたのほうが安全な気がする。

参考

Can you delete multiple branches in one command with Git? - Stack Overflow

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