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?

More than 1 year has passed since last update.

git main(自分のいるbranch)以外のbranchを全削除

Last updated at Posted at 2022-08-11

main・develop以外の「mainにマージ済み」のローカル・リモートブランチ削除

git checkout main
git branch -r --merged main | grep -vE "develop|main" | cut -d "/" -f2- | xargs -t -I{} git push --delete origin {}
git branch --merged|egrep -v '\*|develop|main'|xargs git branch -d

ローカルブランチ

main以外のローカルブランチ削除

git checkout main
git branch | xargs git branch -D

mainとdevelop以外のローカルブランチ削除

git branch --merged|egrep -v '\*|develop|main'|xargs git branch -d

リモートブランチ

fetch前になくなったリモートブランチの削除

git fetch --prune
または
git fetch -p

mainにマージ済みのリモートブランチ全削除

git branch -r --merged main | cut -d "/" -f2- | xargs -t -I{} git push --delete origin {}

mainにマージ済みのリモートブランチでdevelop(mainも)だけ避けて全削除

git branch -r --merged main | grep -vE "develop|main" | cut -d "/" -f2- | xargs -t -I{} git push --delete origin {}

参考

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?