A tiny CLI that finds local Git branches whose remote-tracking branch is gone — typically because the corresponding PR was merged and the remote branch was deleted — and removes them in one shot.
From source:
git clone https://github.com/<you>/git-sweep
cd git-sweep
pip install -e .git-sweep # dry-run: lists what would be deleted
git-sweep --delete # actually delete them
git-sweep --delete --force # use `git branch -D` (also deletes unmerged)
git-sweep --no-prune # skip `git remote prune` first
git-sweep --remote upstream # prune a different remoteBy default, git-sweep runs git remote prune origin so that remote refs are up to date, then lists every local branch whose upstream is marked [gone].
$ git-sweep
found 3 stale branch(es):
fix/login-redirect (was origin/fix/login-redirect)
feat/user-prefs (was origin/feat/user-prefs)
* release/0.4 (was origin/release/0.4)
dry-run. pass --delete to actually remove them.
The * marker means the branch is currently checked out — it will be skipped on delete, since Git refuses to delete the checked-out branch.
After a few months of feature work, local repos collect dozens of dead branches. git branch -d <name> for each one is annoying. This automates the obvious bulk case while staying conservative: dry-run by default, never delete the current branch, never touch a branch that still tracks a live remote.
- Python 3.10+
- Git on
PATH
MIT