deadbranch
Clean up stale git branches safely.
deadbranch helps you identify and remove old, unused git branches that clutter your repository. It's designed to be safe by default — protecting important branches and requiring explicit confirmation before any deletion.
Demo

Features
- List stale branches — Find branches older than N days (default: 30)
- Safe deletion — Only deletes merged branches by default
- Protected branches — Never touches
main,master,develop,staging, orproduction - WIP detection — Automatically excludes
wip/*anddraft/*branches - Backup creation — Saves deleted branch SHAs for easy restoration
- Dry-run mode — Preview what would be deleted without making changes
- Local & remote — Works with both local and remote branches
Installation
Quick Install (macOS/Linux)
|
Homebrew (macOS/Linux)
npm/npx
# Install globally
# Or run directly
Cargo (from source)
Manual Download
Download pre-built binaries from the GitHub Releases page.
| Platform | Architecture | Download |
|---|---|---|
| Linux | x86_64 (glibc) | deadbranch-VERSION-x86_64-unknown-linux-gnu.tar.gz |
| Linux | x86_64 (musl/static) | deadbranch-VERSION-x86_64-unknown-linux-musl.tar.gz |
| Linux | ARM64 | deadbranch-VERSION-aarch64-unknown-linux-gnu.tar.gz |
| macOS | Intel | deadbranch-VERSION-x86_64-apple-darwin.tar.gz |
| macOS | Apple Silicon | deadbranch-VERSION-aarch64-apple-darwin.tar.gz |
| Windows | x86_64 | deadbranch-VERSION-x86_64-pc-windows-msvc.zip |
Build from Source
# Binary will be at target/release/deadbranch
Quick Start
# List all stale branches (older than 30 days)
# List branches older than 60 days
# Preview what would be deleted
# Delete merged stale branches (with confirmation)
# Delete only local branches
Usage
List Stale Branches
| Option | Description |
|---|---|
-d, --days <N> |
Only show branches older than N days (default: 30) |
--local |
Only show local branches |
--remote |
Only show remote branches |
--merged |
Only show merged branches |
Example output:
ℹ Using 'main' as the default branch for merge detection
Local Branches:
┌──────────────────────┬─────────┬────────┬──────────────┐
│ Branch │ Age │ Status │ Last Commit │
├──────────────────────┼─────────┼────────┼──────────────┤
│ feature/old-api │ 154d │ merged │ 2024-09-01 │
│ bugfix/header-issue │ 89d │ merged │ 2024-11-03 │
└──────────────────────┴─────────┴────────┴──────────────┘
Remote Branches:
┌─────────────────────────────────┬─────────┬────────┬──────────────┐
│ Branch │ Age │ Status │ Last Commit │
├─────────────────────────────────┼─────────┼────────┼──────────────┤
│ origin/feature/deprecated │ 203d │ merged │ 2024-07-15 │
└─────────────────────────────────┴─────────┴────────┴──────────────┘
Delete Stale Branches
| Option | Description |
|---|---|
-d, --days <N> |
Only delete branches older than N days (default: 30) |
--merged |
Only delete merged branches (this is the default) |
--force |
Force delete unmerged branches (dangerous!) |
--dry-run |
Show what would be deleted without doing it |
--local |
Only delete local branches |
--remote |
Only delete remote branches |
Safety features:
- Only deletes merged branches by default
- Requires
--forceto delete unmerged branches - Shows confirmation prompt before deletion
- Extra confirmation for remote branches
- Creates backup file with branch SHAs
Example:
Dry Run Mode
Preview deletions without making any changes:
Configuration
deadbranch stores its configuration in ~/.deadbranch/config.toml.
# Show current configuration
# Set default age threshold
# Set protected branches
# Set exclude patterns
# Open config in your editor
# Reset to defaults
Default configuration:
[]
= 30
[]
= ["main", "master", "develop", "staging", "production"]
= ["wip/*", "draft/*", "*/wip", "*/draft"]
Safety Features
deadbranch is designed to prevent accidental data loss:
| Feature | Description |
|---|---|
| Merged-only default | Only deletes branches already merged to main/master |
| Protected branches | Never deletes main, master, develop, staging, production |
| Current branch | Never deletes the branch you're currently on |
| WIP detection | Excludes branches matching wip/*, draft/*, etc. |
| Confirmation prompts | Always asks before deleting |
| Remote warning | Extra confirmation for remote deletions |
| Backup files | Saves SHA of every deleted branch for restoration |
| Dry-run mode | Preview changes without risk |
Restoring Deleted Branches
Every deletion creates a backup file at ~/.deadbranch/backups/<repo>/backup-<timestamp>.txt.
The backup contains git commands to restore each branch:
# From the backup file:
Simply run the appropriate command to restore a branch.
Pattern Matching
Exclude patterns support glob-style wildcards:
| Pattern | Matches |
|---|---|
wip/* |
wip/experiment, wip/test |
*/draft |
feature/draft, bugfix/draft |
feature/*/temp |
feature/foo/temp, feature/bar/temp |
*test* |
test, testing, my-test-branch |
Requirements
- Git (installed and accessible in PATH)
- A git repository (run from within a repo)
Development
# Run tests
# Run with verbose output
# Build release binary
# Run clippy
Roadmap
-
deadbranch restorecommand -
deadbranch statscommand - Interactive TUI mode
-
--only-mineflag for personal branches - GitHub/GitLab PR detection
- Multiple output formats (JSON, CSV)
- Per-repo configuration
License
MIT License — see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request