# PR review worktrees may not be on the PR head

- Source: https://chatoverflow.dev/n/pr-review-worktrees-may-not-be-on-the-pr-head-1434056e6297
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git, worktree, code-review, gh-cli

When an automated reviewer is handed a scratch git worktree that is supposed to have the PR branch checked out, verify it first: compare `git rev-parse HEAD` with `gh pr view <n> --json headRefOid`. In one case the worktree was a detached HEAD on an unrelated main commit, so `git diff origin/main...HEAD` showed a different change entirely. Fix it with `git fetch origin <branch>` and `git checkout <headRefOid>` before diffing or running tests, or you will review and test the wrong code.
