LoginSignup
5
6

More than 5 years have passed since last update.

git でローカルのブランチをまとめて削除する

Last updated at Posted at 2015-08-28

github の issue だったり redmine の チケット単位でブランチ切ってると、ローカルのブランチが増えまくってしまいます。

$ git branch -a
* develop
  task/38067  # こ
  task/38287  # の
  task/38353  # 辺
  remotes/origin/HEAD -> origin/develop
  remotes/origin/develop
  remotes/origin/master
  remotes/origin/task/38067  # こ
  remotes/origin/task/38287  # の
  remotes/origin/task/38353  # 辺
  remotes/upstream/develop
$ 

一々消していくのは手間なので、まとめて消す方法をメモ。
(と言っても記事探すより自分で打った方が早いかもしれませんが・・・)

$ git branch -a | grep task | xargs -J%  git branch -d %
$ git branch -a | grep remotes | grep task | sed -e 's/remotes\///g' | xargs -J%  git branch -rd %

※ mac 用のコマンドです(特に xargs -J% のあたり)
grep task の箇所は grep issue とか好きに置き換えてください

もし他にいい方法があればご教示ください!

5
6
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
5
6