THE GITHTML FIELD GUIDE

Review a GitHub pull request locally without rushing to run it

You can fetch a GitHub pull request’s head into a new local reference and inspect its commits and diff before checking it out or running code. Verify the repository and request number, preserve existing work, and treat execution as a separate trust decision. A successful checkout does not make an external contribution safe to execute.

Start with the minimum inspection needed

Many review questions can be answered through the patch, surrounding source, and tests without executing the contribution. Read the request’s goal, base, head, and changed files first. Look especially at package scripts, install hooks, build configuration, and other paths that can execute code indirectly. A seemingly small source change can arrive with a harmful supporting script.

Use the existing checkout when it is suitable and preserve unrelated edits before any branch switch. Fetching a separate review ref can leave your working files untouched. Do not automatically create additional worktrees or discard local changes as a prerequisite for reading a pull request; choose the smallest operation that answers the review question.

Fetch to an unused local review branch

The example assumes origin is the base GitHub repository and 123 is the verified pull request number. review/pr-123 must be unused; inspect existing branches first. Fetching the head ref records the proposal locally but does not merge it or execute repository code. The proposal may change later, so record the fetched commit.

  1. Use the actual base reference rather than origin/main when the request targets another branch, and refresh that reference if current comparison context matters.
  2. Inspect the full relevant patch before deciding whether local execution is necessary; do not equate a green visual indicator with a trust assessment.
shell
git remote -v
git branch --list review/pr-123
git fetch origin pull/123/head:review/pr-123
git log --oneline -5 review/pr-123
git diff --stat origin/main...review/pr-123

Run only justified checks in an appropriate environment

If testing is needed, follow the project’s safe local procedure and avoid exposing credentials or sensitive data to unfamiliar code. Confirm the checked-out revision before running commands, and report exactly which checks you performed. A test result for an earlier head does not automatically apply after the author pushes more commits.

When finished, retain or remove the local review branch deliberately according to your task, without affecting the remote contribution. Post findings against the correct revision and distinguish verified failures from unanswered questions. The local checkout is evidence-gathering infrastructure, not an obligation to execute every script supplied by a stranger.

  1. If the question concerns one altered condition, inspect its callers and corresponding tests before deciding to install dependencies. Installation can execute code beyond the changed file. Explain which behavior the static inspection establishes and which runtime assumption would require a separate, appropriately isolated test.
  2. When the author pushes another commit during your local review, compare it with the recorded fetched tip before carrying your findings forward. A fix may invalidate a failure report, while a changed installation script may alter the execution risk. Refresh evidence deliberately rather than silently reviewing two different revisions.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All github documentation workflows guides →

Read as MarkdownAll guides

Review a GitHub pull request locally without rushing to run it · gitHtml