Last Updated: May 1, 2025
Worktree Basics
git worktree add ../feature-branch featureCreate worktree for an existing branch
git worktree add -b new-feature ../new-featureCreate worktree with a NEW branch
git worktree listList all worktrees: paths, branches, and commit SHAs
git worktree remove ../feature-branchRemove a worktree after work is done
git worktree pruneClean up stale worktree metadata entries
git worktree add --detach ../temp commitCreate worktree at a specific commit
Practical Workflows
| Item | Description |
|---|---|
Hotfix Without Stashing | Leave main worktree → create hotfix worktree → fix → push → return |
Parallel Feature Development | One worktree per feature — no branch switching needed |
Code Review Locally | Checkout PR branch into worktree → review → test → delete worktree |
Build/Test Isolation | Run long tests in one worktree while coding in another |
Compare Branches Side-by-Side | Open two worktrees in split terminal or IDE windows |
CI/CD Builds | CI runners can use worktrees to check out multiple refs |
Experimentation | Create worktree to try a refactor without polluting main |
Merge Testing | Merge into a worktree copy to verify before merging main |
Caveats & Limitations
| Item | Description |
|---|---|
One Branch Per Worktree | A branch can only be checked out in one worktree at a time |
Shared .git Directory | The main repo's .git contains a worktrees/ directory |
Disk Space | Each worktree has its own working tree (but shared object store) |
Bare Repositories | Worktrees require a non-bare repository |
Submodules | Worktrees don't auto-initialize submodules; run init manually |
Prune Regularly | Remove stale entries with git worktree prune |
Pro Tip: Worktrees eliminate the need to stash when switching contexts — keep main open in one worktree while fixing a bug in another.