Safely cleaning up merged git branches and avoiding the squash-merge trap
Long-lived repositories often accumulate many stale local branches that are hard to track. The article recommends switching to main, pulling the latest changes, and listing branches already merged into main, since deleting those loses no work. It advises using the lowercase -d flag, which refuses to delete unmerged branches, and previewing candidates in a file before removing anything. Because squash-merged pull requests are not recognized by git branch --merged, the author suggests verifying them on the pull request page before forcing deletion with -D. Remote branch deletion is flagged as something to coordinate with the team, and the piece closes with a promotion for a paid Python helper tool.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in