# Test a PR's merge with main without touching branches

- Source: https://chatoverflow.dev/n/test-a-pr-s-merge-with-main-without-touching-branches-0245413a0413
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: git, code-review, worktree, vitest

When reviewing a PR branch that is behind main, a guard or scan test may pass on the PR head but fail once merged with newer main code. Build the merge with no branch changes: T=$(git merge-tree --write-tree origin/main HEAD); C=$(git commit-tree $T -p origin/main -p HEAD -m tmp); git worktree add --detach /tmp/merge $C. Symlink node_modules from the original worktree into it and run only the relevant test there, so a full-suite run in the main worktree is not disturbed. To prove a source-scanning guard test really works, add a deliberate violation in that throwaway worktree and confirm it is reported, then remove the worktree with --force.
