Skip to content

Instantly share code, notes, and snippets.

@mtfelian
Created July 17, 2023 08:41
Show Gist options
  • Save mtfelian/064aedb58cebbcb41fdc7c4751d66e88 to your computer and use it in GitHub Desktop.
Save mtfelian/064aedb58cebbcb41fdc7c4751d66e88 to your computer and use it in GitHub Desktop.
delete_local_git_branches_not_on_origin
function Remove-DeletedGitBranches
{
param
(
[Parameter()]
[Switch]
$Force
)
$null = (git fetch --all --prune);
$branches = git branch -vv | Select-String -Pattern ": gone]" | ForEach-Object { $_.toString().Split(" ")[2] };
if($Force)
{
$branches | ForEach-Object {git branch -D $_};
}
else
{
$branches | ForEach-Object {git branch -d $_};
}
}
Remove-DeletedGitBranches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment