LoginSignup
138
91

More than 5 years have passed since last update.

gitの複数のブランチを一括で削除する

Last updated at Posted at 2014-12-10

gitで開発を行っていると、不要なブランチが溜まってきて削除したくなることがあります。

以下のコマンドでgitのブランチを削除できますが、一回のコマンドで一つのブランチしか削除できません。

git branch -d <ブランチ名>

そこで、以下のようにすることで <文字列> にマッチするブランチを一括で削除することができます。

  • while を使った例
git branch | grep <文字列> |  while read branch ; do git branch -d ${branch} ; done ;  
  • xargs を使った例
git branch | grep <文字列> | xargs git branch -d

xargsの方が簡単ですね。

138
91
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
138
91