Skip to content

Instantly share code, notes, and snippets.

@x86demon
Created October 21, 2022 09:32
Show Gist options
  • Save x86demon/629bfd3e0ad373adc7b6142fa06d98c2 to your computer and use it in GitHub Desktop.
Save x86demon/629bfd3e0ad373adc7b6142fa06d98c2 to your computer and use it in GitHub Desktop.
Remove local detached branches
#!/bin/sh
# https://stackoverflow.com/questions/13064613/how-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore
git fetch -p ; git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment