Skip to content

Instantly share code, notes, and snippets.

@nimatt
Created November 17, 2017 13:26
Show Gist options
  • Save nimatt/088b4c96863df9b99c73acbe5b13b20e to your computer and use it in GitHub Desktop.
Save nimatt/088b4c96863df9b99c73acbe5b13b20e to your computer and use it in GitHub Desktop.
Git
function Remove-GitBranches {
param(
[int]$CommitsBehind = 20
)
$mergedBranches = git branch --remote --merged |
Where-Object {-not $_.Contains('HEAD')} |
Foreach-Object {$b = $_.Trim(); $b.Substring($b.IndexOf('/') + 1)}
$oldBranches = $mergedBranches |
Where-Object {(git log "origin/$_..origin/master" --oneline).Length -gt $CommitsBehind} |
Foreach-Object {$_.Substring($_.IndexOf('/') + 1)}
$oldBranches |
Foreach-Object {git push origin ":$_"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment