deadbranch
Clean up stale git branches safely.
Table of Contents
- Demo
- Features
- Installation
- Shell Completions
- Quick Start
- Usage
- Safety Features
- Restoring Deleted Branches
- Pattern Matching
- Requirements
- Roadmap
- License
- Contributing
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
π Shell Completions
deadbranch can generate tab-completion scripts for bash, zsh, and fish.
Bash
Requires bash-completion 2.x to be active. On macOS without Homebrew's bash, source the file manually in ~/.bash_profile:
Zsh
Then add the following to your ~/.zshrc before the compinit call (or add it if you don't have one):
fpath=(/.zfunc )
&&
Reload your shell or run exec zsh to activate.
Fish
Fish auto-loads completions from this directory β no extra configuration needed.
π 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
# Show branch health overview
π οΈ 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 |
-y, --yes |
Skip confirmation prompts (useful for scripts) |
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 default branch for merge detection
# 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"]
Config keys
| Key | Aliases | Description |
|---|---|---|
days |
default-days, general.default-days |
Default age threshold in days |
default-branch |
branches.default-branch |
Branch used for merge detection (auto-detected if unset) |
protected-branches |
branches.protected |
Branches that are never deleted |
exclude-patterns |
branches.exclude-patterns |
Glob patterns for branches to skip |
πΎ Backup Management
Every deadbranch clean run automatically creates a backup. Use deadbranch backup to manage those backups.
List backups
# Show a summary of all repositories with backups
# Show backups for the current repository
# Show backups for a specific repository
Restore a deleted branch
# Restore from the most recent backup
# Restore from a specific backup file
# Restore with a different name
# Overwrite an existing branch
Backup statistics
# Show storage usage per repository and overall
Clean up old backups
# Keep the 10 most recent backups for the current repo (default)
# Keep only the 3 most recent backups
# Preview what would be removed
# Skip confirmation prompt
# Clean backups for a specific repository by name
π Branch Statistics
Get a health overview of all branches in your repository:
| Option | Description |
|---|---|
-d, --days <N> |
Age threshold for "stale" classification (default: from config or 30) |
Example output:
βΉ Using 'main' as the default branch for merge detection
Repository Statistics:
ββββββββββββββββββ¬ββββββββ¬ββββββββ¬βββββββββ
β Category β Total β Local β Remote β
ββββββββββββββββββΌββββββββΌββββββββΌβββββββββ€
β All branches β 12 β 7 β 5 β
β Merged β 8 β 5 β 3 β
β Unmerged β 4 β 2 β 2 β
β Stale (>30d) β 6 β 4 β 2 β
β Safe to delete β 5 β 3 β 2 β
ββββββββββββββββββ΄ββββββββ΄ββββββββ΄βββββββββ
Age Distribution:
βββββββββββββββ¬ββββββββ¬βββββββββ
β Age Range β Count β Status β
βββββββββββββββΌββββββββΌβββββββββ€
β < 7 days β 2 β fresh β
β 7β30 days β 4 β fresh β
β 30β90 days β 3 β stale β
β > 90 days β 3 β stale β
βββββββββββββββ΄ββββββββ΄βββββββββ
π‘ Run 'deadbranch clean' to remove 5 safe-to-delete branches
Stats cover all visible branches (respecting protected and exclude patterns) regardless of age, so --days only shifts the stale/safe-to-delete threshold β it doesn't hide branches.
π‘οΈ 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:
You can restore branches manually by running those commands, or use the deadbranch backup restore command.
π€ 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)
πΊοΈ Roadmap
- π₯οΈ Interactive TUI mode
- π€
--only-mineflag for personal branches - π GitHub/GitLab PR detection
- π Multiple output formats (JSON, CSV)
- π Per-repo configuration
β Star History
π License
MIT License β see LICENSE for details.
π€ Contributing
Contributions are welcome! See CONTRIBUTING.md for development setup, commit message conventions, testing requirements, and how to submit a pull request.