Skip to content

Instantly share code, notes, and snippets.

@dwenaus
Last active December 1, 2017 19:39
Show Gist options
  • Save dwenaus/a045cfd5e76f16162a8c69c09de65615 to your computer and use it in GitHub Desktop.
Save dwenaus/a045cfd5e76f16162a8c69c09de65615 to your computer and use it in GitHub Desktop.
a quick way to clean-up local branches which no longer exist remotely
git fetch --all -p; git branch -vv | grep ": gone]" | awk '{ print $1 }' | xargs -n 1 git branch -d
the above command will show which will be deleted. use -D instead of -d to delete them all
tested and works
does not delete local branches which only exist locally and have never existed remotely.
a better version would test whether the branch creates a diff or pr. ie. it's been merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment