| name | Git Worktree Workflow |
| description | This skill should be used when the user asks to "create a worktree", "manage git worktrees", "work on multiple branches simultaneously", "isolate task work", "use bd worktree", or needs guidance on git worktree patterns for task isolation in k2-dev workflows. |
| version | 0.2.0 |
Git Worktree Workflow Skill
Overview
Git worktrees enable working on multiple branches simultaneously by creating separate working directories. In k2-dev, each task gets its own worktree for complete isolation.
Key Benefits: Work on multiple tasks without branch switching, complete isolation prevents conflicts, clean separation of concerns, easy context switching, safe cleanup without losing work.
Reference: See k2-dev-reference.md#git-worktree-basics for core git worktree concepts and commands.
K2-Dev Worktree Pattern
For each task:
- Create worktree:
../beads-{id}/
- Branch:
feature/beads-{id}
- Work in isolation
- PR and merge
- Remove worktree
Creating Worktrees
Using bd worktree (Recommended)
Beads provides integrated worktree management:
bd worktree create beads-123
This creates:
- Directory:
../beads-123/
- Branch:
feature/beads-123
- Links to main repository
- Updates beads context
Location: Worktrees created at ../beads-{id}/ (sibling to main repo) for easy organization and management.
Using Git Directly (Manual Control)
git worktree add ../beads-123 -b feature/beads-123
git worktree add ../beads-123 feature/beads-123
Reference: See k2-dev-reference.md#git-worktree-basics for complete git worktree commands.
Multiple Tickets in One Worktree
When /k2:start receives multiple tickets:
bd worktree create beads-123
Working in Worktrees
Switching Context
cd ../beads-123
pwd
git branch --show-current
git status
Making Changes
Work normally in worktree:
vi src/auth/middleware.ts
git add src/auth/middleware.ts
git commit -m "Add JWT middleware"
git push -u origin feature/beads-123
Returning to Main Repo
cd -
cd ~/projects/my-project
Managing Worktrees
Listing Worktrees
bd worktree list
git worktree list
Output example:
/Users/dev/project abc1234 [main]
/Users/dev/beads-123 def5678 [feature/beads-123]
/Users/dev/beads-456 ghi9012 [feature/beads-456]
Removing Worktrees
After PR is merged:
bd worktree remove beads-123
git worktree remove ../beads-123
git worktree prune
Force remove (if needed):
git worktree remove --force ../beads-123
K2-Dev Workflow Integration
Technical Lead Responsibilities
Creating worktree:
bd worktree create beads-123
cd ../beads-123
pwd
git branch --show-current
bd show beads-123
Cleanup after merge:
cd ~/projects/my-project
bd worktree remove beads-123
git worktree list
Engineer Workflow
Start working:
pwd
bd show beads-123
bd comments beads-123
vi src/feature.ts
During implementation:
git add .
git commit -m "Implement feature X"
git push
Create PR:
gh pr create --title "feat: Add feature X (beads-123)" \
--body "$(cat PR_TEMPLATE.md)"
Multiple Worktrees Simultaneously
Engineer can work on multiple tasks:
cd ../beads-123
vi src/auth.ts
cd ../beads-456
vi src/profile.ts
Branching Strategy
Branch Naming
Standard pattern: feature/beads-{id}
Examples:
feature/beads-123
feature/beads-456
feature/beads-789
Why this pattern:
- Clear association with task
- Easy to identify in PR list
- Consistent and predictable
- Sortable and searchable
Reference: See k2-dev-reference.md#branch-naming
Base Branch
Create worktrees from main/master:
cd ~/projects/my-project
git checkout main
git pull
bd worktree create beads-123
Keeping Up to Date
Rebase on main:
cd ../beads-123
git fetch origin
git rebase origin/main
Merge main (if preferred):
cd ../beads-123
git merge origin/main
Best Practices
DO
✅ Create worktree per task - Each beads ticket gets its own worktree for complete isolation
✅ Use consistent naming - ../beads-{id}/ for location, feature/beads-{id} for branch
✅ Clean up after merge - Remove worktree after PR merged to keep workspace tidy
✅ Verify before creating:
git worktree list | grep beads-123
✅ Stay in worktree context - Work entirely in worktree until PR merged
DON'T
❌ Don't nest worktrees - Keep flat structure, don't create worktree inside another
❌ Don't manually delete worktree directories:
rm -rf ../beads-123
bd worktree remove beads-123
❌ Don't reuse worktree for different tasks - One worktree = one task, create new for new task
❌ Don't forget to push:
git push -u origin feature/beads-123
Troubleshooting
Worktree Already Exists
Error: fatal: '../beads-123' already exists
Solution:
git worktree list
git worktree remove ../beads-123
git worktree prune
Branch Already Exists
Error: fatal: a branch named 'feature/beads-123' already exists
Solution:
git worktree list
git branch -D feature/beads-123
bd worktree create beads-123
Can't Remove Worktree
Error: fatal: validation failed, cannot remove working tree
Solution:
cd ../beads-123
git status
git add . && git commit -m "WIP"
git worktree remove --force ../beads-123
Lost Worktree Directory
Scenario: Worktree directory deleted but git still tracks it
Solution:
git worktree prune
git worktree list
Integration with Beads
Beads tracks worktree association:
bd worktree create beads-123
bd show beads-123
bd worktree list
When reading task context, bd show beads-123 may include:
- Worktree location
- Branch name
- Work status
Workflow Summary
Standard k2-dev workflow:
-
Technical Lead: Create worktree
bd worktree create beads-123
cd ../beads-123
-
Engineer: Work in worktree
git add . && git commit -m "feat: Add feature" && git push -u origin feature/beads-123
-
Engineer: Create PR
gh pr create --title "feat: Feature (beads-123)"
-
After merge, Technical Lead: Clean up
cd ~/projects/my-project
bd worktree remove beads-123
bd update beads-123 --status closed
bd sync
Follow this pattern for consistent, isolated task development with clean separation of concerns.
Reference: See k2-dev-reference.md for git worktree commands, branch naming, and common patterns.