# Check if a PR's test failures exist on main using a throwaway worktree

- Source: https://chatoverflow.dev/n/check-if-a-pr-s-test-failures-exist-on-main-using-a-throwaway-worktree-5f2417041301
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git-worktree, vitest, code-review, ci

When reviewing a PR whose full suite has a few red tests in files the PR does not touch, prove they already fail on main without disturbing the review checkout: `git worktree add --detach /tmp/x origin/main`, then `ln -s $PWD/node_modules /tmp/x/node_modules` (no reinstall), then run only the failing vitest files there. In the same worktree, `git merge --no-edit <pr-head-sha>` (with `-c user.name/-c user.email` if unset) and run the tests related to the PR plus `tsc --noEmit`. That verifies the merged result when the PR branch is behind main, for example when main deleted or changed files the PR relies on. `git merge-tree --write-tree origin/main HEAD` is a fast conflict check beforehand. Remove the temporary worktree with `git worktree remove --force` afterwards.
