If you have followed developer discussions or coding-agent changelogs recently, you have probably seen git worktree mentioned as if it were a new invention. In reality, Git introduced worktrees back in 2015 (version 2.5). The sudden surge in interest has less to do with Git itself and more to do with how modern developer tooling runs.
Here is what a worktree actually does, what it costs you, and why it matters today.
What a Worktree Actually Is
Normally, a Git repository gives you one working directory tied to one branch at a time. Need to look at another branch? You git stash, checkout, do your work, checkout back, and stash pop. It works, but it causes friction, especially if you have a dev server running or uncommitted changes you do not want to touch yet.
A worktree lets you check out multiple branches at once, in separate folders, all sharing the same underlying repository:
# from inside your existing repo, currently on `main`
git worktree add ../myproject-feature-x feature-x
That creates a sibling folder checked out to feature-x. Your original folder stays on main, untouched. Both are functional checkouts of the same repository rather than separate clones.
git worktree list # see everything active
git worktree remove <path> # done with it, clean up
Disk Space Costs: What Actually Gets Duplicated
The .git directory (commit history, refs, objects, and trees) is shared across all worktrees. Git stores that data once, regardless of how many worktrees you create.
What does get duplicated is the set of checked-out files for each branch. On a sample repository measured during testing:
| Size | |
|---|---|
.git (history, shared) | 67 MB |
| Working tree files (duplicated per worktree) | ~76 MB |
Adding a worktree cost roughly +76 MB instead of +143 MB. You are not re-cloning the repository, only checking out an additional set of source files.
What a Worktree Does Not Give You: Your Environment
A worktree only gives you Git-tracked files. Anything ignored by .gitignore or living outside the repository must be configured separately:
node_modules: Always gitignored and never copied across. Each worktree requires its ownnpm install,yarn install, orpnpm installbefore running.- Virtual environments,
.envfiles, and local services: Python virtualenvs, database connections, and local secrets live outside version control, so each worktree needs its own configuration. - Build caches: Local compiler and bundler caches are not shared by default.
A couple of practical notes for frontend projects:
pnpmsoftens the disk cost. It uses a global content-addressable store and hardlinks packages into eachnode_modules. Multiple worktrees add minimal disk overhead even though each still requires an install pass. Standardnpmand classicyarndo not do this; each worktree gets a standalone copy of every dependency.- Do not symlink
node_modulesbetween worktrees unless you are certain both branches have identical dependencies. Ifpackage.jsonor the lockfile diverged between branches, a sharednode_moduleswill cause runtime errors on one of them.
The Other Gotcha: Port Conflicts
If you launch dev servers in two worktrees simultaneously (for instance, running vite in both), both processes will attempt to bind the same default port. The second process either fails outright or grabs another port unpredictably, leading to confusing debugging sessions where you inspect the wrong server.
Common solutions:
- Override the port manually per worktree:
vite --port 3001,next dev -p 3001, orPORT=3001 npm run dev. - Use a local environment file: Place a
.env.localinside each worktree (gitignored) specifying a distinctPORT. - Let the tooling auto-increment: Vite and Next.js can assign the next available port automatically. This works for quick checks, though tracking which branch runs on which port requires attention.
- Containerize with Docker Compose, assigning isolated dynamic port mappings per instance.
There is no built-in port negotiation in Git or npm. You coordinate ports manually, exactly as you would with two distinct repository clones.
Why Worktrees Are Trending Now
Three developments converged:
- Parallel AI coding agents. Tools that run multiple agents concurrently (such as one investigating an issue while another writes tests) require isolated working directories. Worktrees provide isolated checkouts from the same local repository without race conditions or overwriting uncommitted work.
- Higher context-switching overhead. Long-running dev processes, TypeScript language servers, and file-watching containers make the traditional
stashcheckoutstash popcycle slow down local iteration. - A mature feature meeting a new use case. Git worktrees existed quietly for years. Parallel, agent-assisted workflows simply made multi-directory checkouts a practical daily necessity.
Summary
Worktrees solve a clear problem: they share Git history, avoid full repository duplicates, and keep multiple branches active in parallel without stashing. At the same time, they require manual environment management: dependencies must be installed per folder, and dev server ports need coordination. For sequential solo work, standard checkouts are often enough. When running automated coding agents alongside your own workflow, worktrees become indispensable.
Building tooling, dashboards, or full-stack products that need a solid engineering workflow behind them? Partner with the developers at Klickspell.
Need technical precision for your web stack?
Architected for performance & scale.
From modern headless commerce to enterprise infrastructure and clean frontend state systems, Klickspell delivers senior engineering craft without agency bloat.
Keep Reading
Related Engineering Articles
Get Your GitHub Account Started: A Step-by-Step Beginner Developer Guide
A practical walkthrough for new developers: creating a GitHub account, configuring local Git user profiles, setting up SSH keys, and publishing your first repository.
Antigravity Was Draining My Laptop Battery, So I Went Back to Plain VS Code
Antigravity was eating my battery and RAM. Here's the lighter setup I use instead: plain VS Code, Continue with Gemini Flash, Claude Code, and the Antigravity extension to utilize a Google AI Pro subscription.