Skip to content

Instantly share code, notes, and snippets.

@legowerewolf
Last active May 23, 2022 20:17
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 legowerewolf/4b907b52a8563fcc0d5a8c58e501b018 to your computer and use it in GitHub Desktop.
Save legowerewolf/4b907b52a8563fcc0d5a8c58e501b018 to your computer and use it in GitHub Desktop.
Delete all local branches where the corresponding remote tracking branch has been deleted
# Requires PowerShell to be installed. Works well when `fetch.prune` is set to `true`.
# running from Bash
pwsh -c 'git branch -vv | where-object {$_ -like "*: gone]*"} | foreach-object {git branch -D ($_ -split "\s+")[1]}'
# running from within pwsh
git branch -vv | where-object {$_ -like "*: gone]*"} | foreach-object {git branch -D ($_ -split "\s+")[1]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment