Created
March 19, 2022 21:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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