GitWorktree.org logoGitWorktree.org

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

AspectGit BranchGit Worktree
What it isA named pointer to a commit (41-byte ref)A separate working directory linked to the same repo
Disk costEssentially zero (just a ref file)Size of the checked-out files (shares .git objects)
Switching contextgit checkout / git switch— replaces working tree in placecd ../other-worktree— just change directories
Uncommitted workMust stash or commit before switchingLeft untouched in its own directory
Parallel workOne branch active at a time per working directoryMultiple branches active simultaneously
Build / tool stateShared — switching may invalidate cachesIsolated — each worktree keeps its own node_modules, build output, etc.
Object sharingN/AAll worktrees share a single object store and reflog

When to Use a Branch

When to Use a Worktree

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.

Create a worktree for an existing branch
# 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
Create a worktree with a new branch
# Creates branch feature/search AND checks it out in a new worktree
git worktree add -b feature/search ../search-worktree

Commits 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.

Without worktrees (branch-only workflow)
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
With worktrees
# 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 it

Example 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 compare

Example 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-42

Creating a New Branch vs Creating a New Worktree

This is a common point of confusion. Here is a clear breakdown:

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