What Is a Git Worktree? Multiple Branches, One Repo
A git worktree lets you check out several branches at once in separate folders, sharing one .git history without cloning the repo again.
A git worktree is a separate, linked working directory attached to the same repository, letting you have several branches checked out at once — each in its own folder — without cloning the repository multiple times or stashing your current changes to switch context.
The problem it solves
A normal git repository has exactly one working directory checked out to exactly one branch at a time. If you’re deep in a feature branch and need to urgently check out main to fix a bug, you’re stuck: commit or stash your in-progress work, switch branches, do the fix, switch back, and pop the stash. It works, but it interrupts your flow and risks losing track of what was staged.
The common workaround was to clone the repository a second time into another folder. That works, but it duplicates the entire .git history on disk, requires a second remote fetch to stay in sync, and gives you two independent repositories to keep straight — commits made in one don’t automatically show up in the other without a push and pull.
How worktrees work
A worktree adds a new checkout that shares the same underlying object database and refs as the original repository, but keeps its own independent working directory and index (staging area).
# From inside an existing repo, create a worktree for a branch
git worktree add ../myrepo-hotfix hotfix-branch
# Create a worktree AND a new branch in one step
git worktree add -b feature/new-thing ../myrepo-feature
Each command above creates a new folder alongside your main checkout, with that specific branch already checked out inside it. You can cd into either folder and work independently — edit files, stage changes, run tests, commit — and both worktrees see the same commit history, branches, and tags, because they point at the same .git object store under the hood.
List and remove worktrees with:
git worktree list
git worktree remove ../myrepo-hotfix
What worktrees are good for
- Context switching without stashing. Keep your feature branch’s working directory exactly as it is while you check out
mainin a second folder to fix something urgent. - Running a long build or test suite on one branch while coding on another. Since each worktree has its own file state, a build in one won’t be disturbed by edits in the other.
- Comparing two branches side by side — open both folders in your editor and diff files directly on disk instead of running
git diffin your head. - Reviewing a pull request locally without disturbing your current branch’s uncommitted work.
Worktrees vs cloning again vs stashing
| Worktree | Second clone | Stash and switch | |
|---|---|---|---|
| Disk usage | Shares one .git object store | Duplicates full history | None extra |
| Setup speed | Fast — no network fetch | Slow — full clone or fetch | Instant |
| Simultaneous branches | Yes, unlimited | Yes, unlimited | No, one at a time |
| Risk of lost context | Low | Low | Moderate — easy to forget a stash |
| Stays in sync automatically | Yes, same refs | No, needs separate fetch/pull | N/A |
A caveat: one branch per worktree
Git won’t let you check out the same branch in two worktrees simultaneously — it exists specifically to avoid two working directories silently drifting out of sync with the same branch pointer. If you try, git will tell you the branch is already checked out elsewhere. This is a feature, not a limitation: it keeps the mental model simple, since a branch’s working state lives in exactly one place at a time.
Worktrees fit naturally into workflows that already lean on branching, like the review and cleanup steps around a git rebase — you can rebase a branch in one worktree while leaving your main working copy untouched. They’re also handy in monorepo setups, where checking out a second branch to compare build output is common; see what a monorepo is for more on that kind of project structure.
Getting started
Worktrees are a built-in git feature, not a plugin, so there’s nothing to install beyond git itself. The git worktree add command works in any modern git installation and modifies only your local checkout — nothing about the remote repository changes. When you’re done with a worktree, git worktree remove cleans up its folder and registration; if you delete the folder manually instead, run git worktree prune to clear the stale reference.
The takeaway
A git worktree gives you a second (or third, or fourth) working directory checked out to a different branch, all sharing one .git history — no duplicate clone, no stash-and-switch dance. Reach for it whenever you need to work on more than one branch at the same time: urgent hotfixes, side-by-side comparisons, or keeping a long-running build isolated from active edits.
Tagged
Keep reading
The Lycoris Team · · 3 min read What Is Git? Version Control, Explained for Beginners
Git is a distributed version control system that tracks changes to code and enables collaboration. Learn the core concepts and everyday workflow.
Takina · · 4 min read What Is Semantic Versioning (SemVer)?
Semantic versioning encodes compatibility into a version number's three parts — major, minor, patch — so dependents know what a version bump might break.
The Lycoris Team · · 5 min read Git Rebase vs. Merge: A Practical Guide
When should you rebase and when should you merge? A clear, example-driven breakdown of the trade-offs, plus a simple workflow you can adopt today.