Git Worktrees Cheat Sheet

Git worktrees — manage multiple working directories from a single repository, ideal for hotfixes, parallel features, and code reviews.

Last Updated: May 1, 2025

Worktree Basics

git worktree add ../feature-branch feature
Create worktree for an existing branch
git worktree add -b new-feature ../new-feature
Create worktree with a NEW branch
git worktree list
List all worktrees: paths, branches, and commit SHAs
git worktree remove ../feature-branch
Remove a worktree after work is done
git worktree prune
Clean up stale worktree metadata entries
git worktree add --detach ../temp commit
Create worktree at a specific commit

Practical Workflows

ItemDescription
Hotfix Without StashingLeave main worktree → create hotfix worktree → fix → push → return
Parallel Feature DevelopmentOne worktree per feature — no branch switching needed
Code Review LocallyCheckout PR branch into worktree → review → test → delete worktree
Build/Test IsolationRun long tests in one worktree while coding in another
Compare Branches Side-by-SideOpen two worktrees in split terminal or IDE windows
CI/CD BuildsCI runners can use worktrees to check out multiple refs
ExperimentationCreate worktree to try a refactor without polluting main
Merge TestingMerge into a worktree copy to verify before merging main

Caveats & Limitations

ItemDescription
One Branch Per WorktreeA branch can only be checked out in one worktree at a time
Shared .git DirectoryThe main repo's .git contains a worktrees/ directory
Disk SpaceEach worktree has its own working tree (but shared object store)
Bare RepositoriesWorktrees require a non-bare repository
SubmodulesWorktrees don't auto-initialize submodules; run init manually
Prune RegularlyRemove 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.