Skip to content

docs: how to set up a git worktree, and why inheritance hides the gaps - #860

Merged
blove merged 1 commit into
mainfrom
blove/document-worktree-setup
Aug 30, 2026
Merged

docs: how to set up a git worktree, and why inheritance hides the gaps#860
blove merged 1 commit into
mainfrom
blove/document-worktree-setup

Conversation

@blove

@blove blove commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

A git worktree gets a fresh checkout but no npm install. Node resolves modules by walking up, so a worktree created inside this repo silently inherits the main checkout's ~1,300 packages and mostly works. That inheritance is the whole problem: the gaps don't fail at setup, they fail an hour into a task, looking like something you just broke.

I hit four of them this week. They look unrelated and have four distinct causes:

Symptom Why inheritance doesn't cover it
Failed to resolve import "./license-public-key.generated.js" postinstall-generated and gitignored — exists in no fresh checkout
Cannot find module 'posthog-node' (website build) installed only into apps/website/node_modules, never hoisted; the walk up from WORKTREE/apps/website/ never passes through the main checkout's
Could not resolve "node_modules/katex/dist/katex.min.css" referenced by literal path from the workspace root — no module resolution, so no upward walk to inherit through
Next.js inferred your workspace root, but it may not be correct (cockpit build) turbopack resolves its own workspace root and won't compile outside it

One command fixes all four: npm ci, once per worktree.

Also documents what not to do

Don't hand-copy packages from the main checkout. This is what I'd been doing, and it's what my own notes recommended — both were wrong. A partial copy pulls a package without its transitive dependencies (copying next traded one error for a worse Cannot find module 'picocolors' cascade), and a mistargeted cp into a not-yet-existing directory copies the package as node_modules, splatting its files at the root. The list of packages to copy also keeps growing.

Don't run npm install in a worktree on macOS — it rewrites package-lock.json and drops the Linux @next/swc-* bindings, breaking CI. npm ci installs strictly from the lockfile and never writes it.

Verified, not assumed

I'd never actually run the remedy I was about to document, so I ran it in this worktree first:

  • npm ci → exit 0
  • package-lock.json byte-identical afterwards (diff -q clean) — confirming the "never rewrites the lockfile" claim directly rather than citing docs
  • all four gaps closed: licensing key generated, posthog-node in apps/website/node_modules, katex CSS at the worktree root, next resolvable (1,322 packages)
  • nx build cockpit went from failing to exit 0 — the same build I'd confirmed fails on pristine main in this worktree
  • nx build website also exit 0

Docs-only change; no code touched.

🤖 Generated with Claude Code

A worktree gets a fresh checkout but no npm install. Node walks up for
node_modules, so a worktree inside this repo silently inherits the main
checkout's ~1300 packages and mostly works — which is why the gaps surface
as unrelated-looking failures deep into a task instead of up front.

Documents `npm ci` as the one-time setup step, with the four failure
signatures hit while working in a worktree this week. They look unrelated
and have four distinct causes:

- postinstall-generated + gitignored (licensing key) — in no fresh checkout
- un-hoisted workspace dep (posthog-node, only in apps/website/node_modules)
  — the walk up from WORKTREE/apps/website never passes through MAIN's
- literal path reference (katex css, resolved from workspace root) — no
  module resolution, so nothing to inherit through
- turbopack resolving its own workspace root (cockpit build)

Also records the two things not to do: hand-copying packages from the main
checkout (a partial copy pulls a package without its transitive deps, and a
mistargeted cp can overwrite node_modules itself), and `npm install` on
macOS (rewrites the lockfile and drops the Linux @next/swc-* bindings).

Verified rather than assumed — ran `npm ci` in this worktree: exit 0,
package-lock.json byte-identical afterwards, all four gaps closed, and
`nx build cockpit` went from failing on pristine main to exit 0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
threadplane Ready Ready Preview Aug 30, 2026 1:23am

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@github-actions

github-actions Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Claude finished @blove's task in 0s —— View job


I'll analyze this and get back to you.

@blove
blove enabled auto-merge (squash) August 30, 2026 01:21
@blove
blove merged commit e01f6dc into main Aug 30, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant