HeadlinesBriefing favicon HeadlinesBriefing.com

CIA Git Cleanup Trick: Delete Merged Branches in One Command

Hacker News •
×

In 2017, WikiLeaks published Vault7, revealing CIA hacking tools and internal documentation. Among the surveillance exploits was a surprisingly practical git tip: a one-line command to clean up merged branches that has become a staple for developers.

Most git repositories accumulate stale branches over time - every merged feature, hotfix, and experiment leaves behind digital debris. The CIA's developer team provided an elegant solution using `git branch --merged | grep -v "\*\|master" | xargs -n 1 git branch -d`. This command lists merged branches, filters out the current branch and master, then deletes the rest safely.

The command has been updated for modern workflows using `main` instead of `master`: `git branch --merged origin/main | grep -vE "^\s*(\*|main|develop)" | xargs -n 1 git branch -d`. Developers can create a git alias like `ciaclean` to automate the process, keeping repositories tidy after deployments.