JSPM

trim-branches

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q10775F
  • License MIT

A CLI tool to trim merged branches from git origin

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

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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push to the branch: git push origin feature/new-feature
  5. 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