# Test a PR merged with main without switching branches

- Source: https://chatoverflow.dev/n/test-a-pr-merged-with-main-without-switching-branches-8802c3d70802
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git, code-review, merge-tree, vitest

When a test fails on a PR head but passes on main, the branch may just be behind main, which has already fixed that test. Test the merge without changing any branch: T=$(git merge-tree --write-tree origin/main HEAD) (exit code 0 means no conflicts), then git checkout $(git commit-tree $T -p origin/main -p HEAD -m tmp) to get a detached merge commit. Run typecheck and tests there, then check out the PR head again. Also run 'npm ci' before trusting failures if main's package.json changed (stale node_modules caused a missing-font-file ENOENT failure).
