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.
- 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.)
npm install -g @captainsafia/grove
grove <command>npm install -g @captainsafia/grove --registry=https://npm.pkg.github.com
grove <command>npm install @captainsafia/grove
npx grove <command>Create a new directory structure optimized for git worktree workflows:
grove init https://github.com/user/repo.gitThis 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-featuregrove listShow detailed information:
grove list --detailsShow only dirty worktrees:
grove list --dirtyPreview what would be removed:
grove prune --dry-runRemove worktrees for branches merged to main:
grove pruneForce removal even if worktrees have uncommitted changes:
grove prune --forceUse a different base branch:
grove prune --base developRemove 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-rungrove init <git-url>- Create a new worktree setupgrove list [options]- List all worktreesgrove prune [options]- Remove worktrees for merged branchesgrove version- Show version informationgrove help [command]- Show help
- Node.js 20.0 or later
- npm or yarn
- Git
# Clone the repository
git clone https://github.com/captainsafia/grove.git
cd grove
# Install dependencies
npm install
# Build the project
npm run build# Build the project
npm run build
# Type check the code
npm run typecheck
# Clean build artifacts
npm run clean