Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Delete old git branches

Delete old git branches

This will delete all branches except for main and feature/foo-bar.

git branch -D `git branch | grep -vE 'main|feature/foo-bar'`

This will delete all branches except for master and branches that begin with kany/SAVE, and kany/hack.

git branch -D `git branch | grep -vE 'master|kany/SAVE|kany/hack'`

Found this snippet from Stackoverflow: Can you delete multiple branches in one command with Git?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment