GIT: How to remove all local and remote branches except specified
Опубликовано пн, 09/23/2019 - 18:36 пользователем MaximHello everyone!
Today I'm going on to tell to you the easiest way how to remove local and remote branches in GIT.
- Remove all local branches except current:
git branch | xargs git branch -D
- Remove all local branches except specified:
git branch | grep -v "master" | grep -v "develop" | xargs git branch -D
- Remove all remote branches except protected (not tested):
export REMOTE_NAME="origin" && git branch -r | xargs -I{} | cut -c$(echo -n $REMOTE_NAME// | wc -m)-100 | xargs git push $REMOTE_NAME --delete
- Remove all remote branches except specified:
export REMOTE_NAME="origin" && git branch -r | grep -v "master" | grep -v "develop" | xargs -I{} | cut -c$(echo -n $REMOTE_NAME// | wc -m)-100 | xargs git push $REMOTE_NAME --delete
Hope this article will help you and save your day!
Enjoy!