Skip to content

Instantly share code, notes, and snippets.

@ghinda
Created March 19, 2015 21:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghinda/0ecebd6cd6a5e51f99be to your computer and use it in GitHub Desktop.
Save ghinda/0ecebd6cd6a5e51f99be to your computer and use it in GitHub Desktop.
Delete all local tracking git branches for which the origin remote branches have been deleted
git for-each-ref --format='%(refname:short)' refs/heads/* | while read branch; do BRANCH_EXISTS=$( git ls-remote --heads origin $branch | wc -l ); if [ $BRANCH_EXISTS -eq 0 ]; then git branch -D $branch; fi;done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment