Skip to content

Instantly share code, notes, and snippets.

@dibble-james
Created March 19, 2022 21:48
Show Gist options
  • Save dibble-james/cd68f44ed92d0df048b192e54a3c1358 to your computer and use it in GitHub Desktop.
Save dibble-james/cd68f44ed92d0df048b192e54a3c1358 to your computer and use it in GitHub Desktop.
A powershell function to delete pushed branches from a local git repo
function clean-branches([Switch]$d = $false) {
if (-not $d) {
Write-Host "Dry-Run, would delete:"
}
git branch -vv | where {$_ -match '\[origin/.*: gone\]'} | foreach {
$branch = $_.split(" ", [StringSplitOptions]'RemoveEmptyEntries')[0]
if ($d) {
git branch -D ($branch)
} else {
Write-Host $branch
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment