Skip to content

Instantly share code, notes, and snippets.

@arjshiv
Created February 23, 2026 06:04
Show Gist options
  • Select an option

  • Save arjshiv/6d18c3dd58726d18ec190ba38758cc05 to your computer and use it in GitHub Desktop.

Select an option

Save arjshiv/6d18c3dd58726d18ec190ba38758cc05 to your computer and use it in GitHub Desktop.
checkout main/master and delete old branches
git checkout master && git pull origin && git remote prune origin && git gc && git for-each-ref --format='%(refname:short)|%(upstream:track)' refs/heads | awk -F'|' '$2 ~ /\[gone\]/ {print $1}' | while read -r b; do [ -n "$b" ] && [ "$b" != "master" ] && git branch -D "$b" 2>/dev/null || true; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment