0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SourceTree】マージ済みのローカルブランチ一覧&一括削除

Posted at

はじめに

SourceTreeでマージ済みのローカルブランチが邪魔なので一括削除したいことがある。
ものすごくある。

手順

# 指定したブランチ(※今回の場合develop)にマージ済み & myname/を含むブランチ一覧
git branch --merged develop | grep 'myname/' | grep -v '\*'

# 指定したブランチ(※今回の場合develop)にマージ済み & myname/を含むブランチを一括削除
git branch --merged develop | grep 'myname/' | grep -v '\*' | xargs git branch -d

# 現在のブランチ(HEAD)にマージ済み & myname/を含むブランチ一覧
git branch --merged | grep 'myname/' | grep -v '\*'

# 現在のブランチ(HEAD)にマージ済み & myname/を含むブランチを一括削除
git branch --merged | grep 'myname/' | grep -v '\*' | xargs git branch -d

git branch --merged BRANCHNAME
指定したブランチにすでにマージ済みのローカルブランチを一覧表示
BRANCHNAMEを省略した場合は現在のブランチ(HEAD)が対象

grep 'myname/'
ブランチ名に「myname/」を含むものだけを抽出
今回はfeature/myname/task_12345のように自分の名前が入っているブランチである前提

grep -v '\*'
現在チェックアウトしているブランチ(先頭に*が付く)を除外
誤って今いるブランチを削除しないための保険

xargs git branch -d
標準入力で渡ってきたブランチ名をまとめて一括削除
一覧表示のみしたい場合は不要

補足

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?