branchguard
Clean up stale and merged git branches.
Install
pip install branchguard
uv tool install branchguard
brew install branchguard
Usage
Scan for branches that can be pruned (dry run, nothing gets deleted):
branchguard
Or explicitly:
branchguard scan
Only show branches that have been merged into main:
branchguard scan --merged
Check against a different target branch:
branchguard scan --target develop
Show branches older than 30 days instead of the default 90:
branchguard scan --days 30
Include remote branches:
branchguard scan --remote
Actually delete the branches:
branchguard scan --force
Get JSON output:
branchguard scan --json
What the output looks like
branchguard
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
┃ Branch ┃ Last Commit ┃ Age (days) ┃ Merged? ┃ Status ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
│ feature/old-login │ 2024-08-15 │ 185 │ yes │ merged │
│ fix/header-bug │ 2024-09-01 │ 168 │ no │ stale │
│ feature/signup │ 2024-11-20 │ 88 │ yes │ merged │
└────────────────────┴─────────────┴────────────┴─────────┴─────────┘
Found 3 branches to prune. Run with --force to delete.
All options
| Option | Short | Default | Description |
|---|---|---|---|
--days |
-d |
90 |
Branches older than this many days are considered stale |
--merged |
-m |
off | Only show branches merged into the target branch |
--target |
-t |
main |
Target branch to check merged status against |
--remote |
-r |
off | Include remote branches |
--force |
-f |
off | Actually delete branches (default is dry-run) |
--json |
-j |
off | Output results as JSON |
--version |
-V |
- | Show version and exit |
Why I built this
I kept accumulating dozens of stale branches in every repo I worked on. Every few weeks I would manually run git branch --merged and delete them one by one, or I would forget and end up with 50+ branches cluttering my local. I wanted a single command that shows me what is safe to delete and lets me clean up in one shot.
License
MIT
Metadata
Release files for branchguard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| branchguard-0.1.0.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| branchguard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.3 kB
Release files / branchguard-0.1.0.tar.gz
| Download URL | branchguard-0.1.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5dbbe97d7482e7091b0ee821e63d79c5b5ed3fdea7f24bdcb5ff3815c283ef61
|
|
BLAKE2b-256 checksum How to use checksums |
35f4db0ddabaa804ddec73d4f6df1712ee69210302a507a77da088ac28e5f22a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / branchguard-0.1.0-py3-none-any.whl
| Download URL | branchguard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17ca5468d69a353e5b1f1800220ed25113a801d8f0dcc327744f8c711f4585f7
|
|
BLAKE2b-256 checksum How to use checksums |
96f858943caf37b38b856d303bb27375feef923f87ed747ae2a50beb657b538e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|