skills/workflow/git-worktrees/SKILL.md
Use when working on multiple features simultaneously. Creates isolated workspaces without branch switching, enabling parallel development.
npx skillsauth add liauw-media/codeassist git-worktreesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Work on multiple features in parallel using git worktrees instead of constantly switching branches.
Git worktrees allow you to have multiple working directories for the same repository, each checked out to a different branch.
Traditional way:
git checkout feature-a
[work on feature-a]
git stash
git checkout feature-b
[work on feature-b]
git stash
git checkout feature-a
git stash pop
With worktrees:
# Both branches available simultaneously in different directories
cd ../project-feature-a # Work on feature-a
cd ../project-feature-b # Work on feature-b
cd ../project-hotfix # Work on hotfix
✅ No stashing: Changes stay in their worktree
✅ Parallel work: Different features in different terminals
✅ Independent testing: Test one branch while coding another
✅ Quick context switching: Just cd to different directory
✅ Clean state: Each worktree is independent
# Basic syntax
git worktree add <path> <branch>
# Create worktree for existing branch
git worktree add ../project-feature-x feature/feature-x
# Create worktree with new branch
git worktree add -b feature/new-feature ../project-new-feature main
# Create worktree from specific branch
git worktree add ../project-hotfix -b hotfix/security-patch main
# List all worktrees
git worktree list
# Output example:
# /path/to/project abc123 [main]
# /path/to/project-auth def456 [feature/authentication]
# /path/to/project-api ghi789 [feature/api-refactor]
# After finishing work and merging the branch
git worktree remove ../project-feature-x
# Or if directory is already deleted
git worktree prune
# Just use cd
cd ../project-auth # Work on authentication
cd ../project-api # Work on API
cd ../project # Back to main worktree
Scenario: Working on authentication (long-term) and need to add quick bug fix
# Setup main project
cd ~/projects/myapp
git checkout main
# Create worktree for authentication feature
git worktree add -b feature/authentication ../myapp-auth main
# Start working on authentication
cd ../myapp-auth
[make changes, run tests, commit]
# Client reports urgent bug while you're working
# No need to stash! Just create worktree for fix
cd ~/projects/myapp
git worktree add -b fix/urgent-bug ../myapp-bugfix main
# Fix the bug in separate worktree
cd ../myapp-bugfix
[fix bug, test, commit, push]
# Create PR for bug fix
gh pr create --title "fix: resolve urgent bug"
# Bug fix merged, clean up
git worktree remove ../myapp-bugfix
# Continue working on authentication without interruption
cd ../myapp-auth
[continue work...]
Scenario: Need to compare behavior between main and your feature branch
# Main worktree
cd ~/projects/myapp # On main branch
# Feature worktree
git worktree add -b feature/new-api ../myapp-feature main
cd ../myapp-feature
[implement feature]
# Test your feature
./scripts/safe-test.sh npm test
# Compare with main branch behavior
cd ~/projects/myapp # Main branch
./scripts/safe-test.sh npm test
# Run both simultaneously in different terminals
# Terminal 1: cd ~/projects/myapp && npm run dev
# Terminal 2: cd ../myapp-feature && npm run dev
# Compare on different ports
Scenario: Reviewing a PR while working on your own feature
# Your work in progress
cd ~/projects/myapp-my-feature
[your work...]
# Colleague asks for code review on their PR
cd ~/projects/myapp
git fetch origin
git worktree add ../myapp-review-pr123 pr-123
# Review the code
cd ../myapp-review-pr123
[review code, run tests, check functionality]
# Add review comments
gh pr review 123 --comment -b "LGTM! Tested locally, works great."
# Clean up review worktree
cd ~/projects/myapp
git worktree remove ../myapp-review-pr123
# Back to your work without any disruption
cd ../myapp-my-feature
[continue working...]
~/projects/
├── myapp/ # Main worktree (main branch)
├── myapp-auth/ # feature/authentication
├── myapp-api/ # feature/api-refactor
└── myapp-bugfix/ # fix/login-error
Pros: Easy to see all worktrees, simple paths Cons: Clutters parent directory
~/projects/myapp/
├── .git/ # Main repo
├── main/ # Main branch worktree
├── worktrees/
│ ├── auth/ # feature/authentication
│ ├── api/ # feature/api-refactor
│ └── bugfix/ # fix/login-error
Pros: Organized, all in one place Cons: Slightly longer paths
~/projects/myapp/
├── .git/
├── production/ # main branch
├── staging/ # staging branch
├── features/
│ ├── authentication/
│ ├── api-refactor/
│ └── user-profile/
└── fixes/
├── login-error/
└── memory-leak/
Pros: Very organized, clear purpose Cons: More complex setup
✅ Name worktree directories clearly (match branch name)
✅ Remove worktrees after branch is merged
✅ Run git worktree prune periodically
✅ Use worktrees for truly parallel work
✅ Keep worktrees in predictable locations
❌ Create too many worktrees (keep it manageable) ❌ Leave stale worktrees around after branches merged ❌ Use worktrees for trivial branch switches ❌ Forget which worktree you're in (use git prompt)
# After feature is merged, remove worktree
git worktree remove ../myapp-feature
# Delete the merged branch
git branch -d feature/feature-name
# Prune any stale worktree references
git worktree prune
# List all worktrees
git worktree list
# Check which branches are merged
git branch --merged
# Remove worktrees for merged branches
for worktree in $(git worktree list --porcelain | grep worktree | cut -d' ' -f2); do
cd $worktree
branch=$(git branch --show-current)
if git branch --merged main | grep -q "$branch"; then
echo "Removing merged worktree: $worktree"
git worktree remove $worktree
fi
done
Use with:
dispatching-parallel-agents - Run multiple agents in different worktreesgit-workflow - Standard git practices apply in each worktreeexecuting-plans - Execute different plans in parallelcode-review - Review PRs in separate worktreesWorkflow:
git worktree addbrainstorming, writing-plans, executing-plansdatabase-backup for each worktreeError: fatal: 'path' already exists
Solution:
# Remove the directory first
rm -rf ../myapp-feature
git worktree add ../myapp-feature feature/feature-name
# Or use a different path
git worktree add ../myapp-feature-v2 feature/feature-name
Error: fatal: 'branch' is already checked out at 'path'
Solution:
# A branch can only be checked out in one worktree at a time
# Either:
# 1. Remove the existing worktree
git worktree remove path/to/existing/worktree
# 2. Or create with different branch name
git worktree add -b feature/feature-name-v2 ../myapp-feature feature/feature-name
Solution:
# Show current worktree path
pwd
# Show current branch
git branch --show-current
# Add to shell prompt (add to .bashrc or .zshrc)
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\w \$(parse_git_branch) $ "
Error: Worktree listed but directory doesn't exist
Solution:
# Prune stale references
git worktree prune -v
# Force remove if needed
git worktree remove --force path/to/worktree
# Create worktree for CI testing
git worktree add ../myapp-ci-test feature/feature-name
# Run CI tests in isolation
cd ../myapp-ci-test
./scripts/safe-test.sh npm run ci-test
# Clean up
cd -
git worktree remove ../myapp-ci-test
# Keep production and staging as worktrees
git worktree add ../myapp-production production
git worktree add ../myapp-staging staging
# Deploy from dedicated worktrees
cd ../myapp-production
git pull origin production
[run deployment script]
cd ../myapp-staging
git pull origin staging
[run staging deployment]
Before creating worktree:
While working in worktree:
After finishing work:
git worktree prune?This skill is based on:
Social Proof: Many professional developers use worktrees for parallel feature development.
Before using worktrees:
Bottom Line: Worktrees enable true parallel development. Use them when you need to work on multiple features simultaneously without constant branch switching. Clean up when done.
development
Use when decomposing complex work. Dispatch fresh subagent per task, review between tasks. Flow: Load plan → Dispatch task → Review output → Apply feedback → Mark complete → Next task. No skipping reviews, no parallel dispatch.
development
# Server Documentation System Set up a documentation system that tracks changes and maintains server/project documentation with Claude Code hooks. ## When to Use - Setting up a new server or development environment - Need to track configuration changes over time - Want automatic documentation of work sessions - Maintaining changelog for infrastructure ## Directory Structure ``` ~/docs/ # User home directory (cross-platform) ├── changelog.md # Global over
development
Delegate tasks to remote Claude Code agent containers for parallel execution, long-running analysis, or resource-intensive operations.
tools
Use when making commits, creating branches, or managing Git operations. Ensures consistent Git practices and proper commit messages.