C.W.K.
Stream
Lesson 11 of 13 · published

Git Integration & Worktrees

~18 min · git, worktrees, checkpoints, rewind, parallel

Level 0🌱 Novice
0 XP0/70 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Parallel work without git stash hell

Claude Code is git-native. Every file edit creates a checkpoint; /rewind or Esc Esc rolls back. The agent commits, branches, rebases, drafts PRs through plain natural language. The bigger pattern: worktrees turn a single repo into N parallel workspaces, one Claude session per worktree, no file collisions.

Worktrees solve the actual problem: you have three half-finished branches, you don't want to git stash through context, and you definitely don't want them sharing a working directory. git worktree add creates a sibling directory pinned to a different branch. Open a Claude session in each. They share commits, they don't share files.

Claude Code's --worktree <name> automates the dance: creates .claude/worktrees/<name>/, branches off origin/HEAD, drops you in. /batch takes it further — decomposes a big refactor into independent units, spawns a background agent per unit in its own worktree, each opens a PR. You review each in isolation.

Code

Parallel sessions, no stash·bash
# Three worktrees in three terminals
claude --worktree feature-auth     "implement OAuth2 login"
claude --worktree bugfix-payment   "fix the null in checkout"
claude --worktree perf-search      "profile and fix slow search"

# All three running simultaneously
# Each touches its own files, all share git history

# Manual equivalent
git worktree add -b feat/x ../x origin/main
cd ../x && claude

# Cleanup when shipped
git worktree remove ../x
/batch — fleet of agents in one shot·bash
# Inside a session
/batch migrate every Express 4 route in src/routes/ to Express 5

# Claude:
# 1. Lists matching files (decomposition)
# 2. Shows you a plan with one unit per file
# 3. On approval: spawns one background agent per unit
# 4. Each agent in its own worktree, implements, runs tests
# 5. Each unit opens its own PR
# You review and merge independently

External links

Exercise

Pick a real repo. Spin up two parallel Claude sessions in two worktrees and have each tackle a different task on the same codebase. Confirm they don't trip over each other's files. Note how this differs from git stash-based parallel work.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.