13
13

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.

Masterブランチにマージ済みのローカルブランチを一括削除する方法

Last updated at Posted at 2016-11-11

目的:
リリースが終わって、Masterブランチにマージ済みの手元のブランチを一括削除したい。

コマンド

git fetch && git branch --merged origin/master | grep -v "^\s*master" | grep -v "^*" | xargs git branch -D

概要

git branch --merged {COMMIT} で特定のCOMMITを指定してマージ済みのブランチを取得できる。そこからカレントブランチとmasterブランチを除外して削除。

ちなみにローカルにあるリモートブランチへの参照は

git remote prune origin

とか

git fetch -p

とかで消せる。

aliasを貼っておくと更に便利

alias git-delete-merged-br='git fetch && git branch --merged origin/master | grep -v "^\s*master" | grep -v "^*" | xargs git branch -D'
13
13
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
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?