Skip to content

Instantly share code, notes, and snippets.

@dalmo3
Last active September 6, 2023 02:54
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 dalmo3/f181a7b521b11c0a671a5454b7ab1977 to your computer and use it in GitHub Desktop.
Save dalmo3/f181a7b521b11c0a671a5454b7ab1977 to your computer and use it in GitHub Desktop.
git prune
# https://stackoverflow.com/questions/13064613/how-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore
# remove local orphan branches
git fetch --prune
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
# remove local merged branches
git branch --merged main | grep -v '^[ *]*main$' | xargs git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment