DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

Git Worktrees and node_modules: Keep Each Branch Correct Without Repeating Busywork

Git worktrees share repository data, not ignored node_modules. Install dependencies from each worktree’s own lockfile, and reduce repeated setup with a shared package store or automation.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes: a new Git worktree needs its own dependency installation when the project relies on node_modules. Git checks out tracked files into a separate working directory; it does not copy ignored local dependencies from another worktree. Install from the new worktree’s own manifest and lockfile, then use package-manager caching or setup automation to make that step less tedious.

Why a new worktree does not include node_modules

A Git worktree is an additional working directory attached to the same repository, not another branch sharing the same checkout. Git describes the feature as allowing a repository to support multiple working trees so you can check out more than one branch at a time (Git worktree documentation).

As an Amazon Associate I earn from qualifying purchases.

The worktrees share repository data, but each has its own checked-out files and some worktree-specific state. For example, each worktree has its own HEAD. By contrast, node_modules is normally local working-tree content and is commonly ignored by Git. A new checkout therefore does not recreate it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create another worktree, you might run:

git worktree add ../feature feature-branch

Git checks out tracked files in ../feature. If the project needs dependencies, install them there using that branch’s package manifest and lockfile.

Install dependencies using the project’s package manager

First check which package manager and lockfile the project uses. Use the repository’s established command rather than choosing one based only on habit. With npm and a committed package-lock.json, npm ci is an option for a clean, lockfile-based install:

cd ../feature
npm ci

If the project uses another package manager or a different lockfile, follow its existing workflow. The important point is that installation happens in the new worktree and uses that worktree’s dependency declarations.

Reduce the repeated cost without sharing a dependency tree

Use a package manager’s shared package store

Separate node_modules directories do not necessarily require separate full copies of every package’s contents. The practical guidance for pnpm describes a content-addressable store that can deduplicate package data while each worktree retains its own dependency arrangement (Git Worktree and node_modules guide; Git Worktree FAQ). Actual disk use and install time depend on the project, package manager, platform, and cache state; the shared store is not a guaranteed performance figure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Automate the install step

A small shell function or project script can create the worktree and run the install command your team already uses. It should detect or explicitly follow the repository’s authoritative lockfile, rather than guessing when multiple package-manager files are present. Automation removes a reminder from the workflow, but it does not make the branches’ dependencies interchangeable.

Avoid automatically copying environment files such as .env as part of this setup. They may contain secrets or configuration that should differ between branches.

Why a shared node_modules symlink is a fragile default

Linking one worktree’s node_modules into another can seem convenient when both branches have identical dependency requirements. But if a branch changes its manifest or lockfile, the linked tree may no longer reflect what that branch declares. The mismatch can be quiet: commands may resolve installed packages even though the worktree’s lockfile specifies something else. Keep separate dependency trees unless you have verified that the requirements and relevant install conditions match, and can keep them matched as branches change.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What npm workspaces do—and do not do

npm workspaces let a project manage local packages beneath a top-level package and link those local packages during installation (npm workspaces documentation). They are not a mechanism that automatically shares one node_modules directory between separate Git worktrees. Treat each worktree as its own checkout and install according to its own repository setup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a workflow that preserves dependency correctness

Approach Dependency correctness Disk use Setup friction Failure clarity
Install separately in each worktree Uses that worktree’s manifest and lockfile. Each worktree has its own dependency arrangement; package contents may be cached or deduplicated depending on the package manager. Requires an install step unless automated. Missing dependencies are usually apparent when a command cannot resolve them.
Use a package manager with a shared store Each worktree can still have its own dependency arrangement. Identical package data may be deduplicated; actual savings vary. Requires using and configuring the package manager’s normal workflow. Worktrees remain distinct, reducing the chance that one branch silently uses another branch’s dependency tree.
Symlink one worktree’s node_modules into another Reliable only while dependency requirements and relevant install conditions match. Avoids maintaining a separate linked directory, though the exact storage outcome depends on the setup. Can avoid a repeated install initially. Can hide a mismatch after manifests or lockfiles diverge.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.