Skip to content

Instantly share code, notes, and snippets.

@stephengodbold
Forked from aaronpowell/.gitconfig
Created July 23, 2012 06:35
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 stephengodbold/3162294 to your computer and use it in GitHub Desktop.
Save stephengodbold/3162294 to your computer and use it in GitHub Desktop.
Script to cleanup merged branches locally
function Cleanup-GitBranches()
{
$branches = git branch --merged | ?{$_ -notmatch "\* master"} | ?{$_ -notmatch "master"} | ?{$_ -notmatch "\* *"} | %{$_.Trim() }
if (-not $branches) {
Write-Host "No merged branches detected"
return
}
Write-Host $branches
$title = "Delete Merged Branches"
$message = "Do you want to delete the already-merged local branches displayed above??"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Delete the remote branches listed."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"Leave the branches alone."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
if ($result -eq 1) {
return
}
$branches | %{ git branch -d "$_" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment