Code Review

Reviewers comment on, approve, or request changes to a pull request before it merges.

Code review is the discussion that happens on a pull request. Reviewers read the diff and leave feedback to improve quality and catch bugs.

Review outcomes

  • Comment — general feedback without a verdict.
  • Approve — the changes look good to merge.
  • Request changes — something must be fixed before merging.

Line comments and suggestions

Reviewers can comment on specific lines and even propose exact edits with a suggestion block, which the author can apply with one click.

Merge strategies

  • Merge commit — keeps every commit plus a merge commit.
  • Squash and merge — combines all commits into one tidy commit.
  • Rebase and merge — replays commits with no merge commit.

Example

Example · bash
# Review a PR locally before approving
gh pr checkout 42     # check out PR #42
# ...run and test it...

# Approve from the terminal
gh pr review 42 --approve

When to use it

  • A senior engineer requests changes on a pull request, leaving inline comments on specific lines explaining why the logic is incorrect.
  • A developer approves a pull request after verifying the tests pass and the code follows the team's style guide.
  • A team uses required code reviews with branch protection so no commit can reach main without at least one approval.

More examples

Check out a PR locally for testing

Downloads the PR's branch locally so you can run tests and verify behaviour before leaving a review verdict.

Example · bash
# Fetch and switch to the PR branch
gh pr checkout 42

# Run the test suite against the PR code
npm test

Leave a review via GitHub CLI

Submits an official GitHub review verdict from the terminal without needing to open the pull request in a browser.

Example · bash
# Approve a PR
gh pr review 42 --approve --body "LGTM! Great error handling."

# Request changes
gh pr review 42 --request-changes --body "Please add input validation."

Add inline comment on a code line

Posts a line-level comment on a specific file and line in the PR diff using the GitHub REST API.

Example · bash
gh api repos/{owner}/{repo}/pulls/42/comments \
  --method POST \
  -f body="Nit: this should use const, not let." \
  -f commit_id="e4a1f3c" \
  -f path="src/utils.js" \
  -F line=17

Discussion

  • Be the first to comment on this lesson.