Git worktrees: work on two branches at once
You're deep in a feature branch, files changed everywhere, and someone asks you to review a PR on a different branch. Your options: stash everything, commit half-finished work, or tell them to wait.
Git worktrees give you a fourth option: check out another branch in a separate directory, without touching your current work at all.
What a worktree is
A worktree is an additional working directory linked to the same repository. Each worktree has its own branch checked out, its own working tree, its own index โ but they all share the same .git data. Changes you commit in one worktree are immediately visible in the other.
The essential commands
The pattern: git worktree add <path> <branch>. The path is where the new working directory lives โ typically a sibling folder next to your main repo.
A real workflow
~/projects/cheatly/ โ main worktree (feature branch)
~/projects/cheatly-review/ โ second worktree (PR review)
- You're working on a feature in
~/projects/cheatly/ - Need to review a PR:
git worktree add ../cheatly-review pr-branch cd ../cheatly-reviewโ the PR is checked out, ready to review- Review, test, leave comments
cd ../cheatlyโ your feature work is exactly where you left it- Done with the review:
git worktree remove ../cheatly-review
No stashing. No committing garbage. No context switching penalty.
When worktrees beat stashing
- Long-running reviews โ stash is for quick switches, worktrees are for when you need both branches open
- Comparing behavior โ run two dev servers side by side
- CI debugging โ check out the failing branch without losing your current context
- Parallel work โ genuinely work on two features, switching between editor windows
When to just stash instead
If the switch takes less than 5 minutes and you don't need both branches simultaneously, git stash is simpler. Worktrees shine when you need to keep both contexts alive.
git log, git branch, and git remote work identically in both. The only difference is which branch is checked out and which files are on disk.For the full reference, see our git cheatsheet and git stash guide.