Created
March 31, 2018 07:17
-
-
Save DanijelMalik/df08be6f48184ecc44851d2a0b933444 to your computer and use it in GitHub Desktop.
This file contains 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
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