Skip to content

Instantly share code, notes, and snippets.

@margauxflores
Last active January 19, 2022 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save margauxflores/16cd5534db9cba4c082babab4c4d2f0b to your computer and use it in GitHub Desktop.
Save margauxflores/16cd5534db9cba4c082babab4c4d2f0b to your computer and use it in GitHub Desktop.
Clean Up Local Git Branches
# For the master branch
# Delete all local branches except master
$ git branch | grep -v "master" | xargs git branch -D
# Delete all local branches except those containing 'master'
$ git branch | grep -ve " master$" | xargs git branch -D
---
# For the develop branch
# Delete all local branches except master
$ git branch | grep -v "develop" | xargs git branch -D
# Delete all local branches except those containing 'master'
$ git branch | grep -ve " develop$" | xargs git branch -D
---
# Delete all merged branches
$ git branch --merged | grep -v \* | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment