Skip to main content

Clean up stale and merged git branches

Project description

branchguard

Clean up stale and merged git branches.

PyPI version Downloads Python version License: MIT

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

branchguard-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

branchguard-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file branchguard-0.1.0.tar.gz.

File metadata

  • Download URL: branchguard-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for branchguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5dbbe97d7482e7091b0ee821e63d79c5b5ed3fdea7f24bdcb5ff3815c283ef61
MD5 4bb972f3b1915b6eaf01aa7f9cca382b
BLAKE2b-256 35f4db0ddabaa804ddec73d4f6df1712ee69210302a507a77da088ac28e5f22a

See more details on using hashes here.

File details

Details for the file branchguard-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for branchguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17ca5468d69a353e5b1f1800220ed25113a801d8f0dcc327744f8c711f4585f7
MD5 f06c021c36a7e65da50a82acd1bff28b
BLAKE2b-256 96f858943caf37b38b856d303bb27375feef923f87ed747ae2a50beb657b538e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page