Delete merged branches Powershell

If you have a lot of branches and want to determine which ones can be deleted because it has been merged to more permanent branches like master, main, dev, release.  Look for the --merged branches and then filter out branches not to delete

git branch --merged | %{$_.trim()}  | ?{$_ -notmatch 'dev' -and $_ -notmatch 'master' -and $_ -notmatch 'main'} | %{git branch -d $_.trim()}

And for a nice click and select option use the Out-GridView powershell extension with the -PassThru option to select the items to delete

Find merged branches: git branch --merged

Pipe selections of Out-GridView to delete: Out-GridView -PassThru

Deletion: git branch -d <branch>

git branch --format "%(refname:short)" --merged  | Out-GridView -PassThru | % { git branch -d $_ }