LoginSignup
0
0

More than 5 years have passed since last update.

特定文字を含むremote branchを一括で削除する方法

Posted at

remote branchの一斉削除

以下コマンドで実施可能。

git branch -a | grep <strings> | sed -e 's% *remotes/origin/%%' | while read branch ; do git push origin :${branch} ; done ;

<string>部分にキーとする特定文字列を入れる。いきなり消してしまうのは怖いので以下で削除候補を確認の上実施するといいと思います。

git branch -a | grep <strings> | sed -e 's% *remotes/origin/%%'

1度マージ済みのbranchに絞るなら--mergedオプションを入れるとより安全です。
(そもそもマージ済みのbranchは削除してしまうべきと思いますが)

ローカルで保持しているremote branch情報を削除

remoteのbranchを削除したあとはローカルに残っているremote/origin/hogeも削除しましょう

以下3つ全て同じです。

git fetch -p
git fetch --prune
git remote prune origin

以下でdry runも可能

git remote prune origin -n
git remote prune origin --dry-run

都度ローカルの掃除をするのが面倒な場合は以下でfetch時に常に-p optionを使用するよう設定可能

git config --global fetch.prune true

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