Back to glossary

Term

Git Worktree

Git worktree allows you to have multiple branches of a repo checked out simultaneously in different directories — without stashing or constant branch-switching.

Git Worktree — explained in more detail

By default, a Git repository has only one active working tree — the directory holding the files of the current branch. Whoever wants to look at another branch must git checkout, which risks all unsaved changes or forces a stash.

What worktrees solve

With git worktree add ../foo-feature feature-branch, Git creates a second working directory based on the same repository. Both directories share the object database under .git/, but have independent working trees — different branches, separate builds, parallel test runs.

Typical use cases

  • Hotfix during feature work: main directory on the feature branch, second worktree on main for the bugfix.
  • Code review: check out the reviewer branch in a second worktree without losing your own state.
  • Parallel AI sessions: every AI instance works in its own worktree — no lock conflicts, no shared build cache.

Constraint

A branch cannot be checked out in two worktrees at the same time. Whoever tries gets an error message — which protects against duplicate work on the same branch.

Entdecke mehr