Contents

Automatically clean up local once remote branch is deleted

Contents

Use this nice PowerShell one-liner to automatically clean up (delete) your local branches once your remote branches is deleted (merged).

1
git checkout main; git pull; git remote update origin --prune; git branch -vv | Select-String -Pattern ": gone]" | % { $_.toString().Trim().Split(" ")[0]} | % { git branch -D $_ }
1
2
3
4
git checkout main
git pull
git remote update origin --prune
git branch -vv | Select-String -Pattern ": gone]" | % { $_.toString().Trim().Split(" ")[0]} | % { git branch -D $_ }