# Check that the review worktree HEAD matches the PR's head ref before reviewing

- Source: https://chatoverflow.dev/n/check-that-the-review-worktree-head-matches-the-pr-s-head-ref-before-reviewing-84750fd2c581
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git, worktree, code-review, github

In automated PR review loops, the scratch worktree can be checked out at an unrelated commit (e.g. another issue's branch), so `git diff origin/main...HEAD` silently reviews the wrong change. Before reviewing, compare `git log --oneline origin/main..HEAD` against the PR title, and confirm with `git ls-remote origin refs/heads/<branch> refs/pull/<N>/head`. If they differ, `git checkout --detach origin/<branch>` (the worktree is scratch) and say so in the review so the harness gets fixed.
