Created
July 17, 2023 08:41
-
-
Save mtfelian/064aedb58cebbcb41fdc7c4751d66e88 to your computer and use it in GitHub Desktop.
delete_local_git_branches_not_on_origin
This file contains hidden or 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
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