From flutter-ddd-builder
This skill should be used when working with "git worktree", "parallel git branches", "worktree merge", "isolated development", or managing multiple branches simultaneously for team-based code generation.
How this skill is triggered — by the user, by Claude, or both
Slash command
/flutter-ddd-builder:git-worktree-managementThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Provides patterns for using git worktree to enable parallel development by multiple agents working on independent branches without conflicts.
Provides patterns for using git worktree to enable parallel development by multiple agents working on independent branches without conflicts.
Enable safe parallel code generation by:
Load this skill when:
# 1. Create worktree for domain
git worktree add ../project-auth feature/auth-domain
# 2. Work in isolated directory
cd ../project-auth
# ... make changes ...
# 3. Commit in worktree
git add .
git commit -m "feat(auth): implement auth domain"
# 4. Switch back to main and merge
cd ../project
git merge --no-ff feature/auth-domain
# 5. Remove worktree
git worktree remove ../project-auth
git branch -d feature/auth-domain
# Pattern: ../project-{domain}
# Branch: feature/{domain}-domain
# Auth domain
git worktree add -b feature/auth-domain ../project-auth
# Post domain
git worktree add -b feature/post-domain ../project-post
# Chat domain
git worktree add -b feature/chat-domain ../project-chat
# Pattern: ../project-ui-{screen}
# Branch: feature/ui-{screen}
# Login screen
git worktree add -b feature/ui-login ../project-ui-login
# Home screen
git worktree add -b feature/ui-home ../project-ui-home
Branch prefix: feature/
Branch format: feature/{domain}-domain or feature/ui-{screen}
Worktree directory: ../{project}-{domain} or ../{project}-ui-{screen}
Each teammate works in its own worktree:
# Teammate receives worktree path
WORKTREE_PATH="../project-auth"
# Navigate to worktree
cd $WORKTREE_PATH
# Verify branch
git branch # Should show feature/auth-domain
# Make changes
# ... create models, services ...
# Stage and commit
git add lib/apps/domain/auth/
git commit -m "feat(auth): add UserModel and AuthService
Co-Authored-By: auth-implementer <agent@flutter-ddd-builder>
"
# Return to main project (orchestrator will merge)
cd -
Orchestrator creates worktrees and assigns to teammates:
# Create worktree for each domain
for domain in auth post chat; do
git worktree add -b feature/${domain}-domain ../${PROJECT_NAME}-${domain}
done
# Spawn teammates with worktree paths
# Each teammate works in assigned worktree
# After all teammates complete, merge each branch
for domain in auth post chat; do
git merge --no-ff feature/${domain}-domain
done
# Cleanup worktrees
for domain in auth post chat; do
git worktree remove ../${PROJECT_NAME}-${domain}
git branch -d feature/${domain}-domain
done
Preserves branch history with merge commit:
git merge --no-ff feature/auth-domain -m "Merge auth domain implementation
- UserModel with Freezed
- AuthService with Riverpod
- API client integration
"
Benefits:
Combines all commits into one:
git merge --squash feature/auth-domain
git commit -m "feat(auth): implement auth domain
- UserModel with Freezed
- AuthService with Riverpod
- API client integration
"
Benefits:
Only when no divergence:
git merge --ff-only feature/auth-domain
Use when:
When multiple domains modify same files:
# Attempt automatic resolution
git merge feature/auth-domain
# If conflict occurs
git checkout --ours conflicted-file.dart # Keep main version
# OR
git checkout --theirs conflicted-file.dart # Keep branch version
git add conflicted-file.dart
git commit -m "Merge auth domain (resolved conflicts)"
For complex conflicts:
# Merge and identify conflicts
git merge feature/auth-domain
git status # Shows conflicted files
# Edit files to resolve
# Look for <<<<<<< HEAD markers
vim lib/apps/ui/router/routes.dart
# After resolution
git add lib/apps/ui/router/routes.dart
git commit -m "Merge auth domain (manual conflict resolution)"
# Remove worktree directory
git worktree remove ../project-auth
# Delete branch (if merged)
git branch -d feature/auth-domain
# Force delete (if not merged)
git branch -D feature/auth-domain
# List all worktrees
git worktree list
# Remove each
git worktree remove ../project-auth
git worktree remove ../project-post
git worktree remove ../project-chat
# Delete branches
git branch -d feature/auth-domain
git branch -d feature/post-domain
git branch -d feature/chat-domain
# Remove worktrees that no longer exist
git worktree prune
# Orchestrator creates 3 worktrees
git worktree add -b feature/auth-domain ../project-auth
git worktree add -b feature/post-domain ../project-post
git worktree add -b feature/chat-domain ../project-chat
# 3 teammates work concurrently
# teammate-1: cd ../project-auth && ...
# teammate-2: cd ../project-post && ...
# teammate-3: cd ../project-chat && ...
# Orchestrator merges sequentially
cd project
git merge --no-ff feature/auth-domain
git merge --no-ff feature/post-domain
git merge --no-ff feature/chat-domain
# Orchestrator cleanups
git worktree remove ../project-auth && git branch -d feature/auth-domain
git worktree remove ../project-post && git branch -d feature/post-domain
git worktree remove ../project-chat && git branch -d feature/chat-domain
# Similar pattern for UI screens
git worktree add -b feature/ui-login ../project-ui-login
git worktree add -b feature/ui-home ../project-ui-home
git worktree add -b feature/ui-profile ../project-ui-profile
# Work, merge, cleanup (same as above)
# Error: worktree '../project-auth' already exists
# Solution: Remove first
git worktree remove ../project-auth
# Then recreate
git worktree add -b feature/auth-domain ../project-auth
# Error: branch 'feature/auth-domain' already exists
# Solution 1: Delete branch
git branch -D feature/auth-domain
# Solution 2: Use existing branch
git worktree add ../project-auth feature/auth-domain
# Error: worktree is locked
# Solution: Unlock first
git worktree unlock ../project-auth
git worktree remove ../project-auth
✅ Use descriptive branch names (feature/auth-domain)
✅ Create worktrees outside main project (../project-auth)
✅ Commit in worktrees before merging
✅ Use --no-ff for clear merge history
✅ Clean up worktrees after merge
✅ Run git worktree prune periodically
❌ Create worktrees inside main project ❌ Share worktree directories between teammates ❌ Leave worktrees after project completion ❌ Force push from worktrees ❌ Modify same files in multiple worktrees simultaneously
For detailed patterns and troubleshooting:
references/worktree-best-practices.md - Advanced worktree patterns# Create
git worktree add -b feature/new-branch ../project-feature
# List
git worktree list
# Remove
git worktree remove ../project-feature
git branch -d feature/new-branch
# Prune stale
git worktree prune
# Merge (in main project)
git merge --no-ff feature/new-branch
Follow these patterns for safe parallel development with git worktrees in Flutter DDD Builder workflows.
npx claudepluginhub ureca-corp/claude --plugin flutter-ddd-builderManage Git worktrees for isolated parallel development. Automates creation, switching, and cleanup with .env copying and .gitignore management. Useful for code reviews and feature work.
Manages git worktrees via unified bash script for parallel development: creates isolated feature environments, lists/switches status, copies .env files, cleans up merged/stale worktrees.
Creates isolated Git worktrees for parallel development, risky refactoring, or multi-feature work without branch switching or conflicts.