wit cleanup
Automatically find and delete branches that have been merged or are stale. Much better than manually checking each branch.
Overview
Over time, repositories accumulate branches that are no longer needed. wit cleanup helps you identify:
- Merged branches - Already merged into main/master
- Stale branches - No commits for a configurable period (default: 30 days)
Usage
Options
Examples
Interactive Cleanup
Output:
Dry Run
See what would be cleaned up without making changes:
Output:
Merged Branches Only
Output:
Custom Stale Threshold
Consider branches stale after 60 days instead of 30:
Protected Branches
The following branches are never suggested for cleanup:
main
master
develop
development
- The current checked-out branch
How It Works
Merge Detection
A branch is considered “merged” if its tip commit is an ancestor of the main branch. This means all commits on that branch are already in main.
Stale Detection
A branch is “stale” if its most recent commit is older than the threshold (default: 30 days). The age is calculated from the commit’s author timestamp.
Tips
Run wit cleanup --dry-run first to review what will be deleted before committing to the cleanup.
Use wit cleanup --merged --force in CI/CD pipelines to automatically clean up after merges.
Deleted branches cannot be easily recovered. Make sure you’ve merged or pushed important work before cleanup.
Automation
Add to your post-merge hooks or CI pipeline:
Or in GitHub Actions: