Git Worktree Examples: 10 Real-World Use Cases
Every example below is a complete, copy-paste workflow. Each one shows a real scenario where git worktree saves significant time compared to branch switching, stashing, or cloning.
1. Emergency Hotfix Without Losing Your Work
You are deep in a feature branch. Production breaks. Instead of stashing, switching, and rebuilding, create a worktree:
# Create a worktree for the hotfix (branching off main)
git worktree add -b hotfix/payment-crash ../project-hotfix main
# Fix the bug
cd ../project-hotfix
# ... edit files ...
git commit -am "fix: handle null payment method"
git push -u origin hotfix/payment-crash
# Open a PR or merge directly
gh pr create --base main --title "fix: payment crash"
# Clean up after merge
cd ../project
git worktree remove ../project-hotfix
git branch -d hotfix/payment-crashYour feature branch is untouched the entire time. No stash, no rebuild, no context loss. See our team hotfix case study for a deeper walkthrough.
2. Review a Pull Request Locally
GitHub's web UI is great for reading diffs, but sometimes you need to run the code. A worktree lets you check out the PR branch without touching your current work:
# Fetch the PR branch
git fetch origin pull/87/head:pr-87
# Create a worktree for the review
git worktree add ../pr-87-review pr-87
# Run the code
cd ../pr-87-review
npm install && npm test
# Done — clean up
cd ../project
git worktree remove ../pr-87-review
git branch -D pr-873. Work on Two Features at Once
Context-switching between branches is expensive when builds take time. With worktrees, both features stay ready:
# Feature A: API redesign
git worktree add -b feat/api-v2 ../project-api main
# Feature B: Dashboard
git worktree add -b feat/dashboard ../project-dash main
# Work on API in one terminal
cd ../project-api && npm install && code .
# Work on dashboard in another terminal
cd ../project-dash && npm install && code .
# Each has its own dev server, its own branch, zero conflicts4. Run Parallel AI Coding Agents
AI coding tools like Claude Code and Cursor modify files as they work. Without isolation, two agents editing the same repo will conflict. Worktrees solve this:
# Claude Code has built-in worktree support
claude --worktree feat/auth
claude --worktree feat/search
claude --worktree fix/perf
# Or set up manually for any AI tool
git worktree add ../project-agent1 -b agent/task-1
git worktree add ../project-agent2 -b agent/task-2
# Open each in a separate Cursor window
cursor ../project-agent1
cursor ../project-agent2See our parallel AI agents guide for advanced patterns.
5. Run Tests While Coding
Your test suite takes 10 minutes. Instead of waiting, let it run in a separate worktree while you keep coding:
# Create a worktree at the current commit
git worktree add ../project-test HEAD
# Start the test suite in the background
cd ../project-test
npm test &
# Keep working in your main checkout
cd ../project
# ... continue editing ...
# When tests finish, check the results
# The worktree is a snapshot — your new edits won't affect it6. Monorepo Release Branches
In a monorepo, you often maintain multiple release branches alongside the main development branch. Worktrees let you keep them all accessible:
# Main development
# (your current directory is already on main)
# Release v2.x maintenance
git worktree add ../monorepo-v2 release/v2
# Release v3.x (upcoming)
git worktree add ../monorepo-v3 release/v3
# Cherry-pick a fix into the v2 release
cd ../monorepo-v2
git cherry-pick abc1234
git push origin release/v2
# Check all active worktrees
git worktree listSee our monorepo release case study for a full walkthrough.
7. Compare Two Branches Side by Side
Need to visually compare implementations? Open both in separate editor windows:
# Check out the old implementation
git worktree add ../project-old release/v1
# Check out the new implementation
git worktree add ../project-new feat/rewrite
# Open both in your editor
code ../project-old
code ../project-new
# Or diff specific files across worktrees
diff ../project-old/src/api.ts ../project-new/src/api.ts8. Bisect a Bug Without Disrupting Work
git bisect checks out different commits, which disrupts your working directory. Run it in a worktree instead:
# Create a worktree for bisecting
git worktree add ../project-bisect HEAD
cd ../project-bisect
git bisect start
git bisect bad HEAD
git bisect good v2.0.0
# Test each commit git checks out
npm test
git bisect good # or: git bisect bad
# ... repeat until the culprit is found ...
# Clean up
git bisect reset
cd ../project
git worktree remove ../project-bisect9. Throwaway Experiments
Want to try a risky refactor without worrying about messing up your checkout? Use a worktree. If it works, merge it. If not, delete it:
# Create a throwaway worktree
git worktree add -b experiment/new-orm ../project-experiment main
cd ../project-experiment
# ... try the new ORM, rewrite queries, see if it works ...
# Option A: it worked — push and create a PR
git push -u origin experiment/new-orm
# Option B: it didn't work — just throw it away
cd ../project
git worktree remove --force ../project-experiment
git branch -D experiment/new-orm10. Bare Repository with Multiple Worktrees
Some developers prefer to clone as a bare repo and create all working directories as worktrees. This keeps the repo directory clean:
# Clone as bare
git clone --bare https://github.com/org/app.git app.git
cd app.git
# Create worktrees for each branch you need
git worktree add ../app-main main
git worktree add ../app-feat feat/dashboard
git worktree add ../app-fix fix/login
# List them
git worktree list
# /home/user/app.git (bare)
# /home/user/app-main a1b2c3d [main]
# /home/user/app-feat d4e5f6a [feat/dashboard]
# /home/user/app-fix 7b8c9d0 [fix/login]This pattern is popular with AI tool setups and teams that always work on multiple branches. See our bare repository guide for details.
Summary
Git worktrees are useful whenever you need two or more branches accessible at the same time. The examples above cover the most common scenarios, from emergency hotfixes to AI-powered parallel development. For the commands behind these examples, see the git worktree add tutorial and cheat sheet.