worktrees
Clean Git worktree management with enforced naming conventions and safety checks
Table of Contents
- Why worktrees?
- Installation
- Quick Start
- Commands
- Naming Convention
- Output Formats
- Development
- Contributing
- License
Why worktrees?
- Never lose work switching between features
- Isolate experiments without affecting main codebase
- Maintain clean history with structured branch names
- Work on multiple features simultaneously without stashing
Installation
From RubyGems
gem install worktrees
From Source
git clone https://github.com/Drew-Goddyn/claude-worktrees.git
cd claude-worktrees
bundle install
rake install_local
Development Setup
bundle exec exe/worktrees --help
Quick Start
# Create a feature worktree
worktrees create 001-user-auth
# List all worktrees
worktrees list
# Switch to a worktree
worktrees switch 001-user-auth
# Check status
worktrees status
# Remove when done
worktrees remove 001-user-auth --delete-branch
Commands
Command | Aliases | Description | Example |
---|---|---|---|
create |
c |
Create new feature worktree | worktrees c 001-feature main |
list |
ls , l
|
List all worktrees | worktrees ls --format json |
switch |
sw , s
|
Switch to worktree | worktrees sw 001-feature |
remove |
rm , r
|
Remove worktree safely | worktrees rm 001-feature --delete-branch |
status |
st |
Show current worktree | worktrees st |
Key Options
-
--format json|csv|text
- Output format (list command) -
--filter clean|dirty|active
- Filter by status (list command) -
--delete-branch
- Also delete Git branch (remove command) -
--force
- Override safety checks -
--switch
- Switch after creating (create command)
Naming Convention
Feature names must follow: NNN-kebab-feature
✅ Valid: 001-user-auth
, 123-api-refactor
, 999-hotfix
❌ Invalid: 1-short
, 001_underscore
, UPPERCASE
, main
Output Formats
Text (default)
* 001-feature active ~/.worktrees/001-feature (from main)
002-bugfix clean ~/.worktrees/002-bugfix (from develop)
JSON
{
"worktrees": [
{
"name": "001-feature",
"status": "active",
"path": "~/.worktrees/001-feature",
"base_ref": "main"
}
]
}
CSV
name,status,path,branch,base_ref,active
001-feature,active,~/.worktrees/001-feature,001-feature,main,true
Development
Run Tests
bundle exec rake spec # All tests
bundle exec rake spec:unit # Unit tests only
bundle exec rake spec:integration # Integration tests
Project Structure
lib/worktrees/ # Ruby source code
├── commands/ # CLI command classes
├── models/ # Data models
└── git_operations.rb # Git interface
exe/worktrees # CLI entry point
spec/ # RSpec test suite
Architecture
- CLI Layer: dry-cli for command parsing
- Business Logic: WorktreeManager coordinates operations
- Git Operations: Safe shell-out to git commands
- Testing: RSpec + Aruba with real repositories
Contributing
- Fork the repository
- Create feature branch:
git checkout -b my-feature
- Write tests:
bundle exec rake spec
- Make changes and ensure tests pass
- Submit pull request
Follow Ruby community conventions and write tests for new features.
License
Built with Ruby 💎