2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gitでマージ済みの不要なブランチを一括削除

Posted at

Gitでリソースを管理していると、徐々にマージ済みのブランチが溜まっていきます。定期的に不要なブランチを削除しているのですが、毎回コマンドを打つのも面倒なので、aliasに設定してCOOL :sunglasses: にします。

aliasの設定

[alias]
  refresh = "!f () { git checkout $1; git pull --prune; git branch --merged | egrep -v '\\*|master|develop' | xargs git branch -d; };f"

使い方

$ git refresh develop

説明

  1. 指定されたブランチに checkout
  2. pull --prune でリモートの変更をローカルに反映し、リモートにて削除されたブランチをローカルからも削除
  3. branch --merged でマージ済みのブランチ一覧を取得
  4. egrep -v で(3)から masterdevelop を除いた一覧を取得
  5. xargs で(4)の内容を順に処理し branch -d でブランチを削除

補足

refresh の後に指定したブランチを引数にして処理します。egrep -v で除外するブランチを指定しているので、環境に合わせて追加 or 削除してください。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?