Claude Skills Guide

Claude Code for Git Worktree Workflow Tutorial

Managing multiple features, bug fixes, or experiments simultaneously can quickly become chaotic in Git. Switching between branches means stashing changes, losing context, or dealing with merge conflicts. Git Worktree solves this problem by letting you check out multiple branches simultaneously in separate directories. Combined with Claude Code, you get a powerful workflow for parallel development that keeps your mental model clean and your productivity high.

This tutorial shows you how to set up Git Worktree, integrate it with Claude Code, and apply practical patterns for managing complex projects.

What is Git Worktree and Why Use It

Git Worktree allows you to have multiple working directories linked to a single Git repository. Instead of stashing your current work or creating new clones, you can check out different branches in different directories. Each worktree has its own working directory, staging area, and Git index, but they share the same .git database.

The typical workflow looks like this:

# Your main worktree (default location)
~/project/

# A feature branch worktree
~/project-feature-auth/

# A bugfix worktree  
~/project-bugfix-login/

This separation means you can work on multiple tasks without context switching. Claude Code can help you manage these worktrees intelligently, creating them on demand and keeping track of which worktree handles which task.

Setting Up Git Worktree

Before integrating with Claude Code, let’s establish the basic worktree setup. Create a worktree for a new feature branch:

cd ~/project
git worktree add ../project-feature-auth feature/oauth-authentication

This creates a new directory at ../project-feature-auth with the feature/oauth-authentication branch checked out. You can now work on authentication without affecting your main working directory.

To list all worktrees:

git worktree list

Expected output:

~/project                        main    ab12345 [main]
~/project-feature-auth           feature/oauth-authentication  ab12345

Remove a worktree when done:

git worktree remove ../project-feature-auth

Integrating Claude Code with Worktree Workflow

Claude Code becomes particularly powerful when managing multiple worktrees. The key is organizing your project structure so Claude can understand which worktree corresponds to which task.

Creating a Claude Skill for Worktree Management

Create a skill that helps manage worktrees:

---
name: worktree-manager
description: Manages Git worktrees for parallel feature development
---

You help manage Git worktrees for parallel development. When asked to create a worktree:

1. Use descriptive directory names like `project-feature-{name}` or `project-bugfix-{issue}`
2. Create the worktree from the appropriate branch (typically main or develop)
3. Update a WORKTREES.md file in the repository root with current worktree status

When asked to switch contexts:
- Save your current progress in the active worktree
- Provide the command to cd to the target worktree

Always maintain a clean WORKTREES.md tracking file showing:
- Worktree path
- Branch name
- Current task/status
- Last updated timestamp

Save this as skills/worktree-manager.md and load it with Claude.

Tracking Worktrees with a Manifest

Create a WORKTREES.md file in your repository root that Claude can read and update:

# Project Worktrees

| Path | Branch | Task | Status |
|------|--------|------|--------|
| ../project-feature-auth | feature/oauth-authentication | OAuth 2.0 integration | In Progress |
| ../project-bugfix-login | fix/login-timeout | Login timeout bug | Review |

Claude can query this file to understand your current context and suggest worktree switches when appropriate.

Practical Workflow Patterns

Pattern 1: Feature Branch Development

When starting a new feature, let Claude guide the worktree creation:

# In your main project directory with Claude Code active
Claude: "Create a new worktree for the payment-refactor feature"

Claude will execute:

git worktree add ../project-feature-payment-refactor -b feature/payment-refactor

Now you have an isolated environment. Make changes, commit frequently, and when ready:

# Switch back to main
cd ~/project
git worktree remove ../project-feature-payment-refactor
git branch -d feature/payment-refactor  # After merging

Pattern 2: Bug Fix Context Switching

When a critical bug arrives while mid-feature:

# Current state: working in feature-auth worktree
# Bug arrives: production login timeout

# Let Claude help you switch contexts
Claude: "Switch to main and create a worktree for the login bug fix"

Claude creates:

cd ~/project
git worktree add ../project-bugfix-login -b fix/login-timeout
echo "Now run: cd ../project-bugfix-login"

You now have isolated environments for both tasks. Neither affects the other.

Pattern 3: Review and Testing

Use worktrees for isolated testing:

# Create a worktree from a pull request branch
git fetch origin pull/123/head:pr-123
git worktree add ../project-pr-123 pr-123

Claude can run different test suites in each worktree without interference:

# In project-feature-auth
npm test

# In project-bugfix-login (different terminal)
npm test

Advanced Worktree Tips

Shared Dependencies, Separate State

Worktrees share node_modules if you use a monorepo tool like pnpm workspaces or Lerna. However, each worktree has its own:

This means you can run builds and tests independently.

Handling Large Repositories

For large repositories, worktrees save significant time:

# Instead of cloning multiple times (each clone = full history)
git clone git@github.com:org/large-repo.git
git worktree add ../large-repo-feature feature/new-ui

# Both worktrees share the same .git objects
# No duplicate cloning needed

Worktree Cleanup

Regular maintenance keeps things tidy:

# Remove stale worktrees (deleted externally)
git worktree prune

# List all worktrees including pruned
git worktree list --porcelain

Common Pitfalls and Solutions

Pitfall: Forgetting which worktree you’re in

Solution: Add this to your shell prompt or use the WORKTREES.md manifest that Claude maintains.

Pitfall: Accidentally editing the wrong branch

Solution: Use the worktree path in your terminal title or explicit cd commands. Claude can help by confirming the current worktree context before making changes.

Pitfall: Merge conflicts when integrating branches

Solution: Work in isolated worktrees until features are complete. Use git rebase in the feature worktree before merging to keep history clean.

Conclusion

Git Worktree combined with Claude Code creates a powerful paradigm for parallel development. By maintaining separate worktree directories, you eliminate context-switching costs, keep features isolated until ready, and enable Claude to help manage your entire project’s development state.

Start small: create one worktree for your next feature, maintain the WORKTREES.md manifest, and let Claude guide your workflow. You’ll wonder how you managed without it.

The combination of Claude Code’s task management and Git Worktree’s parallel development capability represents a significant productivity leap for developers handling multiple concurrent tasks.

Built by theluckystrike — More at zovo.one