Skip to content

Instantly share code, notes, and snippets.

@marcusshepp
Created February 17, 2022 15:32
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 marcusshepp/f8a367860a7861fdd2b8ab0523e553b8 to your computer and use it in GitHub Desktop.
Save marcusshepp/f8a367860a7861fdd2b8ab0523e553b8 to your computer and use it in GitHub Desktop.
delete branches
cd ~/projects/da/da_ui
$branches = (git branch) | Out-String
$branches = $branches.Split([Environment]::NewLine)
for ($num = 0; $num -lt $branches.Count; $num++) {
$branch = $branches[$num] -replace '\s',''
if (![string]::IsNullOrEmpty($branch) -and !($branch -match "Release_Candidate") -and !($branch -match "master")) {
$answer = read-host "delete this branch? ${branch}
${[Environment]::NewLine} y == delete locally
${[Environment]::NewLine} 0 == delete local and remote
${[Environment]::NewLine} n == do not delete ${[Environment]::NewLine}"
if ($answer -eq "y") {
git branch -D $branch
} elseif ($answer -eq "o") {
git branch -D $branch
git push origin --delete $branch
} elseif ($answer -eq "n") {
write-output "Not Deleting: ${branch}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment