1
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?

git syncでいらないブランチをきれいさっぱり

1
Posted at

こんにちは。はしもとかずさです

みなさんはいつもPR出してますか?

PRをたくさん処理していくと問題になってくるのがブランチの多さです

git fetch origin --prune とかでリモートで削除済み(merged)を消すことはできますが、ローカル側のブランチは消えません

そこで!!

git config --global alias.sync '!f() { git pull --prune && git for-each-ref --format="%(refname:short) %(upstream:track)" refs/heads | awk '\''$2 == "[gone]" {print $1}'\'' | xargs -r git branch -d; }; f'

この魔法を実行したあとに git sync を git pull/fetch の代わりに行うと、リモートで消されたブランチでローカルに変更がなければ安全に削除してくれるようになります

1
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
1
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?