Reviewing code
Overview
Code review is the practice of having someone else read a change before it’s merged. It catches bugs, shares knowledge about the codebase, keeps style consistent and helps everyone learn. On GitHub, reviews happen inside pull requests.
Doing a review
1. Understand the goal
Read the PR’s title, description and linked issue first. Ask: what problem does this solve, and is this the right approach? Design problems are much cheaper to fix before you’ve debated variable names.
2. Read the diff
On the PR’s Files changed tab, GitHub shows every change. Useful features:
- Viewed checkboxes on each file track your progress through big PRs.
- Hide whitespace (in the settings cog) removes indentation-only changes.
- Click a line number to comment on it, or drag across several lines to comment on a range.
From the terminal:
gh pr view 2 # description, status, reviewers
gh pr diff 2 # the full diff3. Run it
For anything beyond a trivial change, check the branch out and try it:
gh pr checkout 2This creates a local branch for the PR (even from a fork), so you can run the app and the tests. CI results help, but nothing replaces actually using a feature.
4. Comment
Good review comments are specific, kind and actionable:
| Less helpful | More helpful |
|---|---|
| “This is wrong.” | “This sums prices but ignores quantity — a cart with 3 teas totals £3, not £9.” |
| “Rename this.” | “d is hard to follow; maybe deliveryDate?” |
| “Why?” | “What’s the reason for caching here? I’m worried about stale prices after an update.” |
Label how important a comment is, so authors know what blocks merging: many teams prefix minor points with “nit:” (a small, optional suggestion) and questions with “question:”.
Suggestions
For small, concrete fixes, write a suggestion in a line comment:
```suggestion
<h1>About</h1>
```The author sees a Commit suggestion button that applies your change directly — no copying and pasting.
5. Submit the review
Line comments are collected into a review. When you’re done, choose:
- Comment — feedback without a decision.
- Approve — you’re happy for it to be merged.
- Request changes — it shouldn’t be merged until your points are addressed. (Repository rules can make this block the merge.)
gh pr review 2 --approve --body "Looks good!"
gh pr review 2 --request-changes --body "…"
gh pr review 2 --comment --body "…"What to look for
- Correctness: does it do what it says? Edge cases — empty lists, errors, slow networks, large inputs?
- Tests: are the important cases tested? Would a test fail if the code were wrong?
- Readability: will someone understand this in six months? Are names clear?
- Design: does it fit the existing structure, or duplicate something that exists?
- Security: user input escaped? Secrets kept out? Permissions checked?
- Scope: unrelated changes should be in another PR.
Leave formatting and style to automated tools (formatters, linters in CI) — reviewers’ time is better spent on things machines can’t check.
Requesting reviewers automatically
A CODEOWNERS file (in .github/, the root, or docs/) maps paths to the people or teams responsible for them:
# .github/CODEOWNERS
* @acme/web-team
/docs/ @asha
/src/payments/ @acme/paymentsGitHub requests a review from the matching owners on every PR, and branch rules can require their approval.
Receiving a review
Being reviewed is a skill too:
- Assume good intent. Comments are about the code, not you.
- Respond to every comment — fix it, or explain why not. Resolve conversations once addressed.
- Push fixes as new commits while the review is in progress, so reviewers can see what changed since they last looked. Tidy up (or squash-merge) at the end.
- Re-request review when you’re ready for another look (the circular arrow next to the reviewer’s name).
- Say thanks. Reviewers are giving you their time.
Review etiquette for teams
- Review promptly — waiting days for a review stalls the author and makes conflicts likelier. Many teams aim for within one working day.
- Keep reviews small — encourage small PRs; a 2,000-line PR gets a skim, not a review.
- Praise good work in reviews, not just problems.
- If a discussion goes back and forth more than a couple of times, talk (call or chat) and write the conclusion in the PR.
The goal of review isn’t to find fault — it’s to ship better code together. Be the reviewer you’d want to have.
Review a teammate’s pull request
Ask a friend to open a pull request on your practice repository — or open one yourself from a second branch. Review it from the terminal: list open PRs, read the description and diff, check the branch out locally to try it, and leave a review. Then practise both outcomes: request changes with a constructive comment, and (after a fix is pushed) approve. Write one comment as a GitHub *suggestion* block that the author can apply with one click.
# Inside your practice repository, with gh signed in
# 1. List open PRs and pick one (e.g. number 2)
# 2. Read the description and the diff
# 3. Check it out locally and try it
# 4. Request changes with a helpful comment
# 5. After the author pushes a fix: update, re-check, approve# Inside your practice repository, with gh signed in
# 1. List open PRs and pick one (e.g. number 2)
gh pr list
# 2. Read the description and the diff
gh pr view 2
gh pr diff 2
# 3. Check it out locally and try it
gh pr checkout 2 # creates a local branch for the PR
# …open the page, run the tests…
# 4. Request changes with a helpful comment
gh pr review 2 --request-changes --body "Thanks — the page looks great! One thing before merging:
the heading should be an <h1> for accessibility, since it's the page title. Suggested fix on line 1."
# On the website you can comment on a specific line with a suggestion block:
# ```suggestion
# <h1>About</h1>
# ```
# 5. After the author pushes a fix: update, re-check, approve
gh pr checkout 2 # run again to fetch the author's new commits
gh pr review 2 --approve --body "Looks good, thanks for the quick fix!"
git switch mainSummary
- Code review catches bugs, spreads knowledge and keeps code consistent — every change gets a second pair of eyes.
- Start with the description, then the overall design, then the details; run the code if the change is non-trivial.
- Comment on specific lines, explain why, and use suggestion blocks for small concrete fixes.
- Finish with Comment, Approve or Request changes; CODEOWNERS can request the right reviewers automatically.
- As an author, respond to every comment, push fixes as new commits, and assume good intent.