Skip to main content

Git Delete Local Merged Branches

·1 min

Every once in a while I like to clean up my local Git repo and remove all of the local branches that have been merged with a branch on the remote. Rather than doing this one branch at a time, here’s a PowerShell one liner to do it for you (credit to this SO answer).

git branch --merged | ?{-not ($_ -like "*master")} | %{git branch -d $_.trim()}

It’s relatively safe, as it will explicitly ignore master and uses the little-d delete and --merged options.

For the curious, that SO answer also contains a bash variant for those in *nix consoles.