Git 2.56: Clean Up Merged Branches with git branch --delete-merged
Every few months I run git branch in a repository I work with every day and see a long list: fix-..., add-..., try-.... Most of these branches are pull requests that were merged weeks ago. Git doesn’t delete them by itself, so they just stay there. Until now, I cleaned them up with a one-liner like this: git branch --merged origin/main | grep -vE '^\*|^ *main$' | xargs git branch -d It works, but it’s easy to get wrong. If you forget the grep, main is in the list too. Every branch is compared with the one ref you typed. And there is no way to say “please keep this one”. ...