Package Exports
- trim-branches
- trim-branches/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (trim-branches) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Trim Branches
A CLI tool to trim merged branches from your git origin remote. Keep your repository clean by automatically identifying and deleting branches that have been merged into your main branch.
Features
- ๐ Smart Detection - Automatically finds branches merged into main/master
- ๐ก๏ธ Safe Defaults - Preserves important branches like
develop
by default - ๐ฅ Dry Run Mode - Preview what will be deleted before making changes
- ๐จ Beautiful Output - Colored output with branch information and commit details
- โก Fast - Built on Node.js for cross-platform compatibility
- ๐ค Interactive - Confirmation prompts to prevent accidents
Installation
Global Installation (Recommended)
npm install -g trim-branches
Local Installation
npm install trim-branches
npx trim-branches --help
Usage
Basic Usage
# Preview what would be deleted (recommended first step)
trim-branches --dry-run
# Delete merged branches with confirmation
trim-branches
# Delete without confirmation prompts
trim-branches --force
Advanced Usage
# Use a different main branch
trim-branches --main master
# Also remove develop branch if merged
trim-branches --no-keep-develop
# Combine options
trim-branches --main master --force --no-keep-develop
Options
Option | Alias | Description | Default |
---|---|---|---|
--main <branch> |
-m |
Set the main branch name | main |
--dry-run |
-d |
Show what would be deleted without deleting | false |
--force |
-f |
Skip confirmation prompts | false |
--no-keep-develop |
Also remove develop branch if merged | Keep develop | |
--help |
-h |
Show help message | |
--version |
-V |
Show version number |
Examples
1. Safe Preview
trim-branches --dry-run
Output:
๐ Starting merged branch cleanup...
๐ก Fetching latest changes from origin...
๐ Finding merged branches...
๐ Found the following merged branches:
โข feature/user-auth
Last commit: a1b2c3d Add login functionality
Author: John Doe (2 days ago)
โข bugfix/header-styling
Last commit: d4e5f6g Fix header alignment
Author: Jane Smith (1 week ago)
๐ DRY RUN: The above branches would be deleted from origin
๐ก Run without --dry-run to actually delete them
2. Interactive Deletion
trim-branches
๐ Starting merged branch cleanup...
๐ก Fetching latest changes from origin...
๐ Finding merged branches...
๐ Found the following merged branches:
โข feature/user-auth
โข bugfix/header-styling
โ ๏ธ This will permanently delete the above branches from origin!
? Are you sure you want to continue? (y/N) y
๐๏ธ Deleting merged branches from origin...
โ
Deleted origin/feature/user-auth
โ
Deleted origin/bugfix/header-styling
๐งน Cleaning up local tracking branches...
๐ Cleanup complete!
โ
Deleted: 2 branches
๐ Remaining remote branches: 3
๐ก Tip: Run 'git branch -vv' to see local branches tracking deleted remotes
Safety Features
Protected Branches
By default, these branches are never deleted:
- Your main branch (specified with
--main
) develop
(unless--no-keep-develop
is used)HEAD
and other git references
Confirmation Required
Unless you use --force
, you'll always be asked to confirm before deleting branches.
Detailed Information
Before deletion, you'll see:
- Branch name
- Last commit hash and message
- Author name
- Relative date of last commit
Requirements
- Node.js 14.0.0 or higher
- Git repository with origin remote
- Git command line tools installed
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature
- Commit your changes:
git commit -am 'Add new feature'
- Push to the branch:
git push origin feature/new-feature
- Submit a pull request
License
MIT License - see LICENSE file for details.
Changelog
1.0.0
- Initial release
- Basic branch pruning functionality
- Dry run mode
- Interactive confirmations
- Colored output
- Cross-platform support