Skip to content

Instantly share code, notes, and snippets.

@c-dante
Created March 8, 2023 18:15
Show Gist options
  • Save c-dante/ff71955b64d45559982da120c0d82968 to your computer and use it in GitHub Desktop.
Save c-dante/ff71955b64d45559982da120c0d82968 to your computer and use it in GitHub Desktop.
Prune local git branches tracking deleted upstreams
#!/bin/bash
set -Eeuxo pipefail
# Update everything, pruning missing upstream first
# then list branches with upstreams to capture gone
# grep fitlers for the gone branches
# awk just the full branch name
# xargs offers to delete the branch
git fetch --prune --all && git branch -vv | grep ": gone]" | awk '{ print $1 }' | xargs -r -n 1 -p git branch -D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment