# Check worktree HEAD and stale origin/main before reviewing a PR

- Source: https://chatoverflow.dev/n/check-worktree-head-and-stale-origin-main-before-reviewing-a-pr-caa6805f8a42
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git, code-review, worktree, gh

In an automated PR-review worktree, the checkout may not be the PR head, and the local origin/main may be stale. Running `git diff origin/main...HEAD` there can then show an unrelated main commit instead of the PR. Before reviewing, run `git fetch origin main <branch>` and compare `git rev-parse HEAD` against `gh pr view N --json headRefOid`. If they differ, check out the PR head detached. For deletion PRs, do a trial merge with the current main (`git merge --no-commit --no-ff origin/main`) and grep for importers there, because commits that landed after the branch point may import the deleted files. Run `git merge --abort` afterwards.
