Skip to content

CLI tool for managing git worktree-based workflows

License

captainsafia/grove

Repository files navigation

grove

Grove Logo

Grove is a CLI tool that encapsulates the patterns that I use for working with Git worktrees locally on my machine. To learn more about this pattern, you can check out this blog post.

Features

  • Create new Git repo setup with a bare clone to support worktrees
  • List worktrees with creation dates and dirty status
  • Prune worktrees associated with branches merged to main
  • Prune worktrees older than a specified duration (30d, 6M, 1y, etc.)

Installation

Install globally via npm

npm install -g @captainsafia/grove
grove <command>

Install from GitHub Packages

npm install -g @captainsafia/grove --registry=https://npm.pkg.github.com
grove <command>

Install locally in a project

npm install @captainsafia/grove
npx grove <command>

Usage

Initialize a new worktree setup

Create a new directory structure optimized for git worktree workflows:

grove init https://github.com/user/repo.git

This command will:

  • Create a directory named after the repository (e.g., repo/)
  • Clone the repository as a bare clone into repo/repo.git/
  • Configure the remote fetch to support all branches
  • Provide instructions for creating worktrees

After initialization, you can create worktrees:

cd repo
git worktree add main main
git worktree add feature/new-feature origin/feature/new-feature

List all worktrees

grove list

Show detailed information:

grove list --details

Show only dirty worktrees:

grove list --dirty

Prune merged worktrees

Preview what would be removed:

grove prune --dry-run

Remove worktrees for branches merged to main:

grove prune

Force removal even if worktrees have uncommitted changes:

grove prune --force

Use a different base branch:

grove prune --base develop

Remove worktrees older than a specific duration (bypasses merge check):

Note: When using --older-than, the merge status check is bypassed, and all worktrees older than the specified duration will be removed. The --base flag cannot be used with --older-than.

# Remove worktrees older than 30 days
grove prune --older-than 30d

# Remove worktrees older than 6 months
grove prune --older-than 6M

# Remove worktrees older than 1 year
grove prune --older-than 1y

# Preview what would be removed for worktrees older than 2 weeks
grove prune --older-than 2w --dry-run

Commands

  • grove init <git-url> - Create a new worktree setup
  • grove list [options] - List all worktrees
  • grove prune [options] - Remove worktrees for merged branches
  • grove version - Show version information
  • grove help [command] - Show help

Development

Prerequisites

  • Node.js 20.0 or later
  • npm or yarn
  • Git

Setup

# Clone the repository
git clone https://github.com/captainsafia/grove.git
cd grove

# Install dependencies
npm install

# Build the project
npm run build

Development Commands

# Build the project
npm run build

# Type check the code
npm run typecheck

# Clean build artifacts
npm run clean

About

CLI tool for managing git worktree-based workflows

Topics

Resources

License

Stars

Watchers

Forks

Packages