Skip to content

Instantly share code, notes, and snippets.

@kany
Last active February 9, 2022 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kany/fc561b98bf2c38ed160b032fd0b1a8eb to your computer and use it in GitHub Desktop.
Save kany/fc561b98bf2c38ed160b032fd0b1a8eb to your computer and use it in GitHub Desktop.
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