| name | cgit-worktree |
| description | Manage Git worktrees for isolated parallel development. Use when the user wants to work on multiple features in parallel, review code in isolation, or needs a clean workspace. Handles creating, listing, switching, and cleaning up worktrees. |
Git Worktree Manager
Manage Git worktrees for isolated parallel development ā review PRs in isolation, work on features in parallel, or get a clean workspace.
When to Use
- Code review: Isolate review work from in-progress feature work
- Parallel features: Work on multiple features simultaneously
- Clean workspace: Get a fresh copy without stashing
- Cleanup: After completing work in a worktree
Commands
Create a worktree
git worktree add .worktrees/<branch-name> -b <branch-name> main
git worktree add .worktrees/<branch-name> -b <branch-name> <from-branch>
After creating:
- Copy
.env* files from the main repo to the worktree
- Ensure
.worktrees is in .gitignore
- Report the path for the user to
cd into
List worktrees
git worktree list
Show which worktree is current (marked with active indicator).
Switch to a worktree
cd .worktrees/<name>
If the name isn't provided, list available worktrees and ask the user to pick one using #askQuestions.
Clean up worktrees
git worktree list
git worktree remove .worktrees/<name>
git worktree prune
Always confirm before removing. Never remove the current worktree.
Workflow Integration
With /review
- Check current branch
- If already on the target branch ā stay, no worktree needed
- If on a different branch ā offer worktree using
#askQuestions:
- Yes ā create worktree, cd into it
- No ā proceed with PR diff on current branch
With /cwork
Always offer the choice using #askQuestions:
- New branch (live work on current worktree)
- Worktree (parallel work in isolation)
Setup Details
Directory structure
.worktrees/
āāā feature-login/ # Worktree 1
āāā feature-notifications/ # Worktree 2
āāā ...
.env file handling
After creating a worktree, copy environment files:
for f in .env .env.local .env.test .env.development .env.production; do
[ -f "$f" ] && cp "$f" ".worktrees/<name>/$f"
done
.gitignore management
Ensure .worktrees is gitignored:
grep -q '.worktrees' .gitignore 2>/dev/null || echo '.worktrees' >> .gitignore
Key Principles
- Worktrees are lightweight ā shared git objects, no repo duplication
- Always confirm destructive actions ā don't remove without asking
- Copy .env files ā worktrees need environment config to function
- Keep .worktrees gitignored ā these are local development artifacts
- Prefer worktrees over stash ā cleaner workflow, no accidental conflicts