https://github.com/sulthonzh/branchcleanup
Smart Git branch cleanup CLI that detects squash-merged branches with interactive deletion
https://github.com/sulthonzh/branchcleanup
branch cleanup cli developer-tools git github merge squash
Last synced: 5 days ago
JSON representation
Smart Git branch cleanup CLI that detects squash-merged branches with interactive deletion
- Host: GitHub
- URL: https://github.com/sulthonzh/branchcleanup
- Owner: sulthonzh
- License: mit
- Created: 2026-05-27T21:42:20.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-06-20T11:07:06.000Z (10 days ago)
- Last Synced: 2026-06-20T13:08:18.617Z (10 days ago)
- Topics: branch, cleanup, cli, developer-tools, git, github, merge, squash
- Language: TypeScript
- Size: 132 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Branch Cleanup
Smart Git branch cleanup CLI that detects squash-merged branches with interactive deletion.
## Features
- π **Detects all types of merged branches**: Regular merged + squash-merged (GitHub's default)
- π― **Interactive deletion**: Safe confirmation prompts for each branch
- π‘οΈ **Safety checks**: Protected branch detection and dry-run mode
- π **Clear status display**: Shows branch type and safety status
- β‘ **Fast and lightweight**: Minimal dependencies, focused on core functionality
## Installation
```bash
npm install -g branchcleanup
```
## Usage
### List branches
```bash
# List all branches with their status
branchcleanup list
# List with custom stale threshold (60 days)
branchcleanup list --stale-threshold=60
# Include remote branches in the list
branchcleanup list --include-remote
```
### Interactive cleanup
```bash
# Interactive cleanup with confirmation prompts
branchcleanup cleanup
# Dry run - show what would be deleted
branchcleanup cleanup --dry-run
# Force delete (bypass confirmation)
branchcleanup cleanup --force
# Include remote branches in cleanup
branchcleanup cleanup --include-remote
```
### Options
```bash
# Show help
branchcleanup --help
# Show version
branchcleanup --version
```
## Examples
### List branches
```
$ branchcleanup list
βββββββββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ
β Branch β Type β Safe to Deleteβ
βββββββββββββββββββββββΌβββββββββββββββΌβββββββββββββββ€
β feature/user-auth β squash-mergedβ β
Yes β
β bugfix/login-page β merged β β
Yes β
β experiment/new-ui β stale-30d β β No (old) β
βββββββββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββ
```
### Interactive cleanup
```
$ branchcleanup cleanup
β Delete feature/user-auth (squash-merged)? [y/N] y
β
Deleted feature/user-auth
β Delete bugfix/login-page (merged)? [y/N] y
β
Deleted bugfix/login-page
β Delete experiment/new-ui ( stale-30d)? [y/N] n
π Skipping experiment/new-ui (user declined)
```
## Development
```bash
# Clone the repository
git clone https://github.com/sulthonzh/branchcleanup.git
cd branchcleanup
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build for production
npm run build
# Run tests
npm test
# Run linting
npm run lint
```
## How It Works
### Branch Detection
The tool detects three types of branches:
1. **Merged branches**: Detected using `git branch --merged`
2. **Squash-merged branches**: Detected by checking if all commits from the branch exist in the target branch
3. **Stale branches**: Branches not touched in the specified number of days (default: 30)
### Remote Branch Support
With the `--include-remote` flag, the tool can also detect and clean up remote branches:
- **Remote merged branches**: Branches merged on the remote repository
- **Remote stale branches**: Remote branches not updated within the threshold
- **Safe deletion**: Remote branches are pushed to `--delete` on their respective remotes
### Safety Features
- **Protected branch detection**: Never deletes `main`, `master`, or other protected branches
- **Confirmation prompts**: Interactive confirmation for each deletion
- **Dry-run mode**: Preview what would be deleted without actually deleting
- **Force mode**: Bypass confirmation for bulk operations
## License
MIT