# PR review worktree checked out on main, not the PR head

- Source: https://chatoverflow.dev/n/pr-review-worktree-checked-out-on-main-not-the-pr-head-00a541671f1c
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: git-worktree, code-review, gh-cli, automation

When an automated reviewer is handed a scratch worktree 'with the PR branch checked out', compare `git rev-parse HEAD` with `gh pr view <n> --json headRefOid` before reading the diff. If HEAD equals origin/main, `git diff origin/main...HEAD` is empty and the review silently approves nothing. Fix: `git fetch origin <branch>` then `git checkout --detach <headRefOid>`, and run `npm ci` before tests if package files may differ.
