Git Worktree vs Branch: What's the Difference?
Branches and worktrees are complementary Git features that solve different problems. A branchis a pointer to a commit — it’s a lightweight reference that tracks a line of development. A worktreeis a physical checkout of a branch into a separate directory on disk. You always use them together: every worktree has a branch checked out, but a branch doesn’t require its own worktree.
Comparison at a Glance
| Aspect | Git Branch | Git Worktree |
|---|---|---|
| What it is | A named pointer to a commit (41-byte ref) | A separate working directory linked to the same repo |
| Disk cost | Essentially zero (just a ref file) | Size of the checked-out files (shares .git objects) |
| Switching context | git checkout / git switch— replaces working tree in place | cd ../other-worktree— just change directories |
| Uncommitted work | Must stash or commit before switching | Left untouched in its own directory |
| Parallel work | One branch active at a time per working directory | Multiple branches active simultaneously |
| Build / tool state | Shared — switching may invalidate caches | Isolated — each worktree keeps its own node_modules, build output, etc. |
| Object sharing | N/A | All worktrees share a single object store and reflog |
When to Use a Branch
- You want to start a new line of development but only work on one thing at a time.
- You’re working on a small change and switching branches is fast (no heavy build step).
- You want to keep your disk usage minimal — branches cost almost nothing.
- You’re collaborating and need to push a named ref for others to pull.
When to Use a Worktree
- You need to work on two branches at the same time — for example, a hotfix while a feature is in progress.
- Your project has a long build or install step (e.g.,
npm install) and switching branches would blow away the cache. - You want to run tests on one branch while continuing development on another.
- You need to compare behaviour between two branches side by side (two dev servers on different ports).
How Branches and Worktrees Work Together
A worktree always has a branch (or detached HEAD) checked out. When you run git worktree add, you are creating a new working directory and checking out a branch in it. Git enforces a rule: the same branch cannot be checked out in two worktrees at once. This prevents conflicting changes to the same ref.
# You're on main in the primary worktree
git worktree add ../hotfix-worktree hotfix/login-bug
# Now hotfix/login-bug is checked out in ../hotfix-worktree
# and main is still checked out here# Creates branch feature/search AND checks it out in a new worktree
git worktree add -b feature/search ../search-worktreeCommits made in any worktree are visible to all other worktrees immediately, because they share the same object database. You can merge, rebase, or cherry-pick across worktrees without fetching.
Practical Examples
Example 1: Hotfix While Feature Is in Progress
You’re deep into a feature branch with uncommitted work and half-built assets. A critical bug report comes in.
git stash
git checkout main
git checkout -b hotfix/critical-bug
# fix the bug, commit, push
git checkout feature/dashboard
git stash pop
# hope nothing conflicts with the stash# Don't touch your current work at all
git worktree add -b hotfix/critical-bug ../hotfix main
cd ../hotfix
# fix the bug, commit, push
cd ../main-worktree
# your feature work is exactly where you left itExample 2: Running Two Dev Servers Side by Side
# Terminal 1 - current branch (main)
npm run dev -- --port 3000
# Terminal 2 - feature branch in a separate worktree
cd ../feature-worktree
npm run dev -- --port 3001
# Open both in your browser and compareExample 3: Code Review in a Separate Directory
# Check out a colleague's PR branch without disrupting your work
git fetch origin pull/42/head:pr-42
git worktree add ../review-pr-42 pr-42
# Open ../review-pr-42 in your editor, run tests, leave notes
# When done:
git worktree remove ../review-pr-42
git branch -d pr-42Creating a New Branch vs Creating a New Worktree
This is a common point of confusion. Here is a clear breakdown:
git branch feature/xcreates a new branch pointer but does not check it out. Your working directory is unchanged.git checkout -b feature/xcreates a branch and switches to it in the current directory. Your working tree now reflects that branch.git worktree add ../feature-x feature/xchecks out the branch into a new directory. Your current directory stays on its original branch.git worktree add -b feature/x ../feature-xcreates a new branch and checks it out in a new directory, in one step.
The key insight: git worktree add doesn’t replace git branch. It replaces the git checkout / git switch step by giving the branch its own directory instead of switching the current one.
Related Pages
- What Is Git Worktree? — A beginner-friendly introduction
- git worktree add — How to create a new worktree
- Worktree vs Clone — Another common comparison