3.7 KiB
3.7 KiB
description: Manage git worktrees for feature isolation
argument-hint: [name] - Actions: create, list, switch, cleanup
Git Worktree Management
Manage isolated git worktrees for feature development. Worktrees provide complete isolation between features, preventing conflicts during parallel development.
Actions
create
Create a new isolated worktree for a feature.
Workflow:
- Validate feature name provided
- Determine project name from current directory
- Create branch:
feature/ab-{feature-name} - Create worktree at:
../ab-worktrees/{project}-{feature-name}/ - Register in
.auto-build-data/worktrees/worktree-registry.json - Display success message with path
Command:
bash .auto-build/scripts/worktree-create.sh {feature-name}
Output:
Created worktree for: feature-name
Branch: feature/ab-feature-name
Path: ../ab-worktrees/project-feature-name/
To work in this worktree:
cd ../ab-worktrees/project-feature-name/
list
List all active worktrees.
Workflow:
- Read
.auto-build-data/worktrees/worktree-registry.json - Verify each worktree still exists (git worktree list)
- Display table:
Active Worktrees: | Feature | Branch | Path | Created | |---------|--------|------|---------| | user-dashboard | feature/ab-user-dashboard | ../ab-worktrees/project-user-dashboard/ | 2h ago |
Command:
bash .auto-build/scripts/worktree-list.sh
switch
Provide instructions to switch to a worktree.
Workflow:
- Look up worktree path from registry
- Verify worktree exists
- Display switch instructions:
To switch to feature-name worktree: cd ../ab-worktrees/project-feature-name/ Or start a new Claude Code session in that directory.
Note: Claude Code sessions are directory-bound, so actual switching requires changing the working directory.
cleanup [feature-name]
Remove completed worktrees.
Workflow: If feature-name provided:
- Look up worktree in registry
- Check if branch is merged to main
- If merged or user confirms: Remove worktree and branch
- Update registry
If no feature-name:
- List all worktrees
- Check which branches are merged
- Offer to cleanup merged ones:
Found 2 merged worktrees: - old-feature (merged 3 days ago) - bug-fix (merged 1 week ago) Remove these? [Yes] [Select] [No]
Command:
bash .auto-build/scripts/worktree-cleanup.sh [feature-name]
Registry Format
.auto-build-data/worktrees/worktree-registry.json:
{
"worktrees": [
{
"name": "user-dashboard",
"branch": "feature/ab-user-dashboard",
"path": "../ab-worktrees/project-user-dashboard/",
"created": "2025-01-15T10:30:00Z",
"status": "active",
"spec": ".auto-build-data/specs/user-dashboard/"
}
]
}
Worktree Location
Worktrees are created outside the project directory to avoid:
- Nested git repository issues
- IDE confusion
- Accidental commits from wrong directory
Structure:
/projects/
├── my-project/ # Main project
│ ├── .auto-build/
│ └── .auto-build-data/
└── ab-worktrees/ # Worktrees directory
├── my-project-user-dashboard/
└── my-project-api-refactor/
Error Cases
- Branch already exists: Ask to use existing or create new
- Worktree path exists: Ask to reuse or choose different path
- Not a git repository: Inform user and abort
- Uncommitted changes: Warn user before creating worktree