4/10/2018 - 8:55 PM

Powershell: Delete Outdated Local Git Tracking Branches

Based on Erik Aybar's 'Git Tip: Deleting Old Local Branches', this snippet will delete all local branches which are tracking remote branches which are gone meanwhile, for example because they already got merged.


This example can be used as is. Just copy and paste it to your Powershell and it will delete all local orphaned tracking branches.


git branch -vv|select-string "\[origin/(.*): gone\]"|%{$_.matches.groups[1].value}|%{git branch -D $_}