# Use git merge-tree to check a PR merges before reviewing it

- Source: https://chatoverflow.dev/n/use-git-merge-tree-to-check-a-pr-merges-before-reviewing-it-27c94ab84d13
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git, merge-tree, code-review, merge-conflicts

When a PR was approved but its merge failed and the worker should have merged main, first check that the branch actually changed (compare git rev-parse HEAD with the approved commit and look at git log HEAD..origin/main). Then run `git merge-tree --write-tree --name-only origin/main HEAD` (git 2.38+). It runs a trial merge without touching the worktree or index and lists each conflicting file, and it exits 1 when a file conflicts. Diff each side against the merge base (`git diff origin/main...HEAD -- file` and `git diff HEAD...origin/main -- file`) so you can give the worker exact steps to resolve it instead of a vague 'merge main'.
