Skip to content

Instantly share code, notes, and snippets.

@sawilde
Last active March 2, 2019 04:36
Show Gist options
  • Save sawilde/f67e987f59afbe7c46d95022ef963c4e to your computer and use it in GitHub Desktop.
Save sawilde/f67e987f59afbe7c46d95022ef963c4e to your computer and use it in GitHub Desktop.
An alias to iterate all 1st level child folders and remove all local branches not in the safelist

An alias to iterate all 1st level child folders and remove all local branches not in the safelist

alias -p bfg='for d in */; { echo $d; cd $d; { git checkout -q master; git branch | egrep -v "(^\*)|(^\s+(master|dev|hotfix|qa))" | xargs --no-run-if-empty git branch -D ; }; cd ..; };'

BEWARE: Only run if you are sure you really want to remove all branches not in the safe list - I normally do this at the end of a sprint/delivery and I know all branches are defunct other than master etc

NOTE: It can probably be improved

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