Skip to content

Instantly share code, notes, and snippets.

@DanijelMalik
Created March 31, 2018 07: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 DanijelMalik/df08be6f48184ecc44851d2a0b933444 to your computer and use it in GitHub Desktop.
Save DanijelMalik/df08be6f48184ecc44851d2a0b933444 to your computer and use it in GitHub Desktop.
param(
[Parameter(Mandatory = $false)]
[string] $Location
)
$oldLocation = Get-Location
Write-Host "Set Git location '$Location" -ForegroundColor Cyan
Set-Location $Location
Write-Host "Switching to (master)..." -ForegroundColor Cyan
& git checkout master | Out-Null
Write-Host "Pruning orphaned branch references..." -ForegroundColor Cyan
& git remote prune origin
Write-Host "Removing orphaned branches..." -ForegroundColor Cyan
$branches = & git branch -vv
foreach ($branch in $branches) {
if ($branch.Contains(": gone")) {
$branchName = $branch.Remove(0, 2) -split " " | Select-Object -First 1
Write-Host "`tBranch: ($branchName)..." -ForegroundColor Magenta
& git branch -D $branchName
}
}
Write-Host "Reset location '$oldLocation" -ForegroundColor Cyan
Set-Location $oldLocation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment