Skip to main content

Git Worktree vs Branch: What Is the Difference?

A branch is a named pointer to a commit. A worktree is a directory with files checked out from a commit, usually a branch. You need a worktree only to have two branches open at the same time.

The Answer​

A branch is a line of history. A worktree is a place to edit files. A normal clone has one worktree, so switching branches swaps the files in that one directory. git worktree add gives you a second directory, so two branches stay checked out side by side.

BranchWorktree
What it isA ref under refs/heads/ that points at a commitA directory with its own files, index and HEAD
Created withgit branch feature or git switch -c featuregit worktree add ../repo-feature feature
CostA few bytesA full copy of the tracked files
Shared across worktreesYes, every worktree sees every branchNo, each worktree has its own uncommitted changes
Removed withgit branch -d featuregit worktree remove ../repo-feature

Use a branch alone when you work on one thing at a time and switching is cheap. Add a worktree when you need two branches live at once: a long build on one while you edit another, a hotfix without stashing, or two coding agents that must not edit the same files.

How They Relate​

Each worktree has one HEAD. It points at a branch, or at a commit when detached. git branch -vv marks branches that another worktree holds with + and shows its path:

+ feature 54d33c8 (/src/repo-feature) init
* main 54d33c8 init
+ new-feature 54d33c8 (/src/repo-new-feature) init

Git lets one branch be checked out in only one worktree. Trying a second checkout fails:

fatal: 'feature' is already used by worktree at '/src/repo-feature'

The two lifecycles are separate. Removing a worktree leaves its branch in place, and Git refuses to delete a branch that a worktree still uses:

error: cannot delete branch 'hotfix' used by worktree at '/src/repo-hotfix'

Inside a worktree you can still switch or create branches. git switch -c other changes which branch that directory holds without affecting any other worktree.

How Treq Handles It​

Treq pairs the two for you. Each workspace gets its own branch and its own working copy under .treq/workspaces/, so one task maps to one branch and one directory. Treq uses its own managed workspaces, not Git worktrees, which lets it rebase stacked workspace branches when their targets move.