Skip to content

Instantly share code, notes, and snippets.

@shanerk
Last active March 18, 2024 19:25
Show Gist options
  • Save shanerk/a300b9f5e5f49de9f2570616350eb1f1 to your computer and use it in GitHub Desktop.
Save shanerk/a300b9f5e5f49de9f2570616350eb1f1 to your computer and use it in GitHub Desktop.
Cleanup deleted branches (PowerShell)
# Step 1: git fetch -p
git fetch -p
# Step 2: git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '$2 == "[gone]" {print $1}' | xargs git branch -D
git for-each-ref --format '%(refname:short) %(upstream:track)' | Where-Object { $_.Split(' ')[1] -eq '[gone]' } | ForEach-Object { git branch -D $_.Split(' ')[0] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment