A pure Bash utility for cleaning up Git branches. Find stale, merged, and squash-merged branches, then delete them interactively with built-in safety protections.
- List all branches with last commit date, author, and age
- Find branches merged into main
- Find branches with no activity in N days
- Interactive deletion with selection
- Protected branch patterns (never deletes main, master, dev, release/*)
- Dry-run mode
- Remote branch cleanup (prune stale tracking refs)
- Squash-merged branch detection
- Branch age histogram visualization
curl -o /usr/local/bin/git-branch-clean https://raw.githubusercontent.com/Anuar-boop/git-branch-clean/main/git_branch_clean.sh
chmod +x /usr/local/bin/git-branch-cleanOr clone and symlink:
git clone https://github.com/Anuar-boop/git-branch-clean.git
ln -s $(pwd)/git-branch-clean/git_branch_clean.sh /usr/local/bin/git-branch-cleangit-branch-clean listBRANCH LAST COMMIT AUTHOR STATUS
---------------------------------------------------------------------------------
feature/auth 2026-01-15 alice 49d ago
bugfix/login 2026-02-28 bob 4d ago [protected]
main 2026-03-03 alice 1d ago (current) [protected]
git-branch-clean mergedgit-branch-clean stale
git-branch-clean stale --days 60 # custom thresholdgit-branch-clean clean
git-branch-clean clean --dry-run # preview without deletingSelect branches to delete:
[1] feature/old-widget (last: 2025-11-03)
[2] bugfix/typo-fix (last: 2025-12-20)
[3] experiment/new-api (last: 2026-01-05)
Enter numbers to delete (comma-separated, 'all', or 'q' to quit): 1,3
Deleted: feature/old-widget
Deleted: experiment/new-api
git-branch-clean remote-clean
git-branch-clean remote-clean --remote upstreamgit-branch-clean squash-mergedgit-branch-clean histogram < 1 week ████████████ 3
< 1 month ████████████████████ 5
< 3 month ████████ 2
< 6 month ████████████████████████████████████████ 10
< 1 year ████████████ 3
> 1 year ████ 1
Total branches: 24
| Flag | Description | Default |
|---|---|---|
-d, --days N |
Stale threshold in days | 30 |
-m, --main NAME |
Main branch name | main |
-r, --remote NAME |
Remote name | origin |
-n, --dry-run |
Preview without changes | off |
-h, --help |
Show help | - |
These branch patterns are never deleted:
main,masterdev,developstagingrelease/*hotfix/*
- Bash 4+
- Git 2.x+
MIT