All skills
Skillintermediate

git-worktrees - Parallel Branch Development

Use when working on multiple branches simultaneously, context switching without stashing, reviewing PRs while developing, testing in isolation, or comparing implementations across branches.

Claude Code Knowledge Pack7/10/2026

Overview

git-worktrees - Parallel Branch Development

Use when working on multiple branches simultaneously, context switching without stashing, reviewing PRs while developing, testing in isolation, or comparing implementations across branches.

  • Purpose - Provide git worktree commands and workflow patterns for parallel development
  • Core Principle - One worktree per active branch; switch contexts by changing directories

Key Concepts

ConceptDescription
Main worktreeOriginal working directory from git clone or git init
Linked worktreeAdditional directories created with git worktree add
Shared .gitAll worktrees share same Git object database (no duplication)
Branch lockEach branch can only be checked out in ONE worktree at a time

Quick Reference

TaskCommand
Create worktree (existing branch)git worktree add <path> <branch>
Create worktree (new branch)git worktree add -b <branch> <path>
List all worktreesgit worktree list
Remove worktreegit worktree remove <path>
Compare files between worktreesdiff <worktree1>/file <worktree2>/file
Get one file from another branchgit checkout <branch> -- <path>
Cherry-pick a commitgit cherry-pick <commit>

Common Workflows

  • Feature + Hotfix in Parallel - Create worktree for hotfix while feature work continues
  • PR Review While Working - Create temporary worktree to review PRs without stashing
  • Compare Implementations - Create worktrees for different versions to diff side-by-side
  • Long-Running Tasks - Run tests in isolated worktree while continuing development

Creating Worktrees

Create and setup git worktrees for parallel development with automatic dependency installation.

/worktrees create <name>
/worktrees --list
ArgumentDescription
<name>Branch name (multi-word supported, e.g., auth system), auto-detects type from keywords like feature, fix, hotfix, refactor
--listList all existing worktrees

How It Works

  1. Type Detection: Auto-detects branch type from name (feature, fix, hotfix, refactor, etc.)
  2. Branch Resolution: Creates or tracks existing local/remote branch
  3. Worktree Creation: Creates sibling directory with pattern ../<project>-<name>
  4. Dependency Installation: Detects project type and runs appropriate install command

Supported Project Types: Node.js (npm/yarn/pnpm/bun), Python (pip/poetry), Rust (cargo), Go, Ruby, PHP

Usage Examples

# Create feature worktree (default type)
> /worktrees create auth system
# Branch: feature/auth-system -> ../myproject-auth-system

# Create fix worktree
> /worktrees create fix login error
# Branch: fix/login-error -> ../myproject-login-error

# Create hotfix while feature work continues
> /worktrees create hotfix critical bug

# List existing worktrees
> /worktrees --list

Comparing Worktrees

Compare files and directories between git worktrees or worktree and current branch.

/worktrees compare [paths...] [--stat]
ArgumentDescription
<paths>File(s) or directory(ies) to compare
<worktree>Worktree path or branch name to compare
--statShow summary statistics only

Usage Examples

# Compare specific file
> /worktrees compare src/app.js

# Compare multiple paths
> /worktrees compare src/app.js src/utils/ package.json

# Compare entire directory
> /worktrees compare src/

# Get summary statistics
> /worktrees compare --stat

# Interactive mode (lists worktrees)
> /worktrees compare

Merging from Worktrees

Merge changes from worktrees into current branch with selective file checkout, cherry-picking, interactive patch selection, or manual merge.

/worktrees merge [path|commit] [--from <worktree>] [--patch] [--interactive]
ArgumentDescription
`<path\commit>`
--from <worktree>Source worktree path or branch name
--patchInteractively select hunks within files
--interactiveGuided merge mode with strategy selection

Merge Strategies

StrategyUse WhenCommand Pattern
Selective FileNeed complete file(s) from another branchgit checkout <branch> -- <path>
Interactive PatchNeed specific changes within a filegit checkout -p <branch> -- <path>
Cherry-Pick SelectiveNeed a commit but not all its changesgit cherry-pick --no-commit + selective staging
Manual MergeFull branch merge with controlgit merge --no-commit + selective staging
Multi-SourceCombining files from multiple branchesMultiple git checkout <branch> -- <path>

Usage Examples

# Merge single file
> /worktrees merge src/app.js --from ../project-feature

# Interactive patch selection (select specific hunks)
> /worktrees merge src/utils.js --patch

# Cherry-pick specific commit
> /worktrees merge abc1234

# Full guided mode
> /worktrees merge --interactive