Skip to content

Lesson 6 of 28Pull requests and code review

Pull Requests That Get Reviewed Fast

Size, split and describe pull requests so reviewers can say yes quickly, then handle review comments and merging like someone the team trusts.

19 min read0/4 questions

Your commits are clean and your branch is up to date. Now someone has to review it. Your pull request has been open for six days. It changes 1,400 lines across 38 files, the description says "Implements saved items, see ticket", and you have posted "could someone take a look?" in the team channel twice. Nobody is being lazy. Each reviewer opened it, saw the size, and decided to do it "when I have a proper hour", which never came. Meanwhile main moved, you have conflicts, and the feature is late. How fast your work ships depends less on how fast you code than on how easy your PRs are to review. This lesson covers sizing and splitting work, writing a description that answers the reviewer's questions before they ask, and handling the review and the merge.

Why size beats everything

The best-known data comes from a SmartBear study of code review at Cisco, covering around 2,500 reviews. Reviewers found defects well when they looked at about 200 to 400 lines at a time, at a pace under about 500 lines an hour, for no more than an hour or so. Beyond that, the number of problems found per line dropped sharply: people stop reading and start skimming. Google's internal review guide makes the same point from experience: around 100 lines is usually a reasonable change, and 1,000 lines is usually too large. Treat these as guidelines, not laws, but the direction is never in doubt.

Small PRs win in every way that matters at work:

  • They get picked up sooner, because a reviewer can finish one between meetings.
  • They get reviewed better, so fewer bugs reach production.
  • They conflict less, because they are open for hours, not days.
  • They are easier to revert, because one change does one thing.

Not every changed line costs review effort. A lockfile, a generated API client or a snapshot file can be thousands of lines that nobody reads line by line. What matters is the number of lines a human must actually think about. The block below estimates that from git diff --numstat main...HEAD output (added, deleted, path), the way a PR-size check in CI might.

Python
import fnmatch # Output of: git diff --numstat main...HEAD (added, deleted, path)NUMSTAT = """\12\t3\tsrc/checkout/total.py48\t0\ttests/test_total.py1630\t1544\tpackage-lock.json220\t0\tsrc/api/__generated__/client.ts9\t9\tsrc/checkout/template_filters.py-\t-\tdocs/flow.png""" IGNORE = ["package-lock.json", "uv.lock", "*__generated__*", "*.snap"] def review_size(numstat): reviewed, skipped = 0, [] for line in numstat.strip().splitlines(): added, deleted, path = line.split("\t") if added == "-": # binary file: no line counts skipped.append(f"{path} (binary)") continue if any(fnmatch.fnmatch(path, p) for p in IGNORE): skipped.append(path) continue reviewed += int(added) + int(deleted) return reviewed, skipped lines, skipped = review_size(NUMSTAT)print("lines a human must review:", lines)print("not counted:", ", ".join(skipped))if lines > 400: print("verdict: too big, split it")elif lines > 200: print("verdict: reviewable, but say where to start")else: print("verdict: small, should get a quick review")
Output
Press Run (⌘ Enter) to see what happens.
Predict the outputPython

In the block above, you delete "*__generated__*" from the IGNORE list and run it again. What is the last line it prints?

IGNORE = ["package-lock.json", "uv.lock", "*.snap"]
Need a nudge? Hints walk you through it.

Splitting big work

"This feature cannot be split" is almost never true. These are the cuts that work, roughly in order of how often you will use them:

  • Refactor first. If the feature needs code moved or an interface changed, ship that as its own PR with no behaviour change. It is easy to approve, and the feature PR shrinks.
  • By layer. A database migration, then the backend endpoint with tests, then the UI. Each can merge on its own if nothing uses it yet.
  • Behind a feature flag. Merge incomplete work switched off. Users see nothing until the flag flips, and you avoid a long-lived branch. Feature flags come back in the CI/CD and releases lesson.
  • Separate the mechanical from the meaningful. A rename across 60 files and a logic change in three should never share a PR.

When the pieces depend on each other and you do not want to wait for each review before starting the next, use stacked PRs. Each branch starts from the previous one, and each PR targets the branch below it instead of main.

Three stacked pull requests
basemainM1pr1-migrationA1U1X

currentwaitingdone

PR 1 adds the saved_items table. It targets main and is about 60 lines.

1/4
git switch pr3-uigit rebase --update-refs main      # rebases the whole stack, moving pr1 and pr2 toogit push --force-with-lease origin pr1-migration pr2-api pr3-ui

In the practice repo, that one rebase reported Updated the following refs with --update-refs: refs/heads/pr1-migration, refs/heads/pr2-api. When PR 1 merges, retarget PR 2 to main (GitHub often does this automatically when the base branch is deleted). Tools such as Graphite automate the bookkeeping. Check what your team uses before inventing your own process.

Quick check
You need to add a 'saved for later' feature: a new table, two API endpoints, a UI panel, and while exploring you also found the cart module needs reorganising first. What is the best first PR?
Need a nudge? A hint rules out a wrong answer.

The description is half the review

A reviewer opens your PR with no context. Every question your description answers is a round trip saved. Most repos have a template in .github/pull_request_template.md; if yours does not, this shape works almost everywhere:

.github/pull_request_template.md
## What and why
One or two sentences on the problem and the outcome. Link the ticket.
Fixes SHOP-482.
 
## How
The approach, and anything you considered and rejected.
Start reviewing at `src/checkout/total.py`; the rest follows from it.
 
## How I tested it
- Unit tests for the 2.5 x 3 case (they fail without this change)
- Checked an order end to end on staging
 
## Screenshots
Before / after, for any UI change. A short video for an interaction.
 
## Risk and rollout
Touches payment capture. Behind the `precise_totals` flag, off by default.
Rollback: turn the flag off; no migration to undo.
 
## Follow-ups
- SHOP-490: remove the old rounding helper once the flag is at 100%

The title matters as much. "Keep full precision in cart totals" tells a reviewer and a future reader what happened; "SHOP-482" or "Fixes" tells them nothing. If the team squash-merges, the title often becomes the commit message on main, so follow whatever format your team uses there (often Conventional Commits, from Commits your teammates thank you for).

The risk and rollout section is what separates juniors from seniors in a description. It answers the reviewer's real fear: "if this is wrong, what breaks and how do we undo it?". "Low risk: copy change only" is a fine answer when true. Writing it also forces you to think about rollback before you need it.

Before you ask anyone

Your first reviewer is you. Open the PR's diff in GitHub (or run git diff main...HEAD) and read it as if a stranger wrote it. The three dots mean "changes on my branch since it split from main", which is what reviewers see. You will find debug prints, commented-out code, a stray file and at least one variable name you now regret. Fixing those yourself saves a review round and a little embarrassment.

Then make sure the checks are green. Asking people to review a PR whose tests fail wastes their time, because the code is going to change anyway. gh pr checks --watch waits for the checks in your terminal.

If you want early feedback on direction before the code is finished, open a draft PR (gh pr create --draft). It says "look at the approach, not the details". GitHub does not auto-request code owners on drafts, and drafts cannot be merged. Mark it ready with gh pr ready when it is.

Put it in order6 steps

Put the steps before requesting review in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.

Guide the reviewer

You know where the risk is; the reviewer does not. Leave comments on your own PR before anyone looks: "This is the important change, the rest is wiring", "I am not sure about this lock timeout, it is a guess from load testing", "Moved unchanged from utils.py". Saying what you are unsure about is not weakness. It points expert attention where it is most useful, and reviewers trust authors who do it.

Clean commits help here too. If your branch is three commits (refactor, fix, test), say "review commit by commit" in the description. GitHub lets reviewers step through a PR one commit at a time.

Choosing reviewers and keeping it moving

Request review from one or two specific people, not "the team". When everyone is asked, nobody feels responsible. Choose by knowledge: someone who owns the area, plus perhaps someone who should learn it.

Many repos automate this with a CODEOWNERS file in .github/, the repository root or docs/. Each line maps a path pattern to people or teams, and the last matching pattern wins. Code owners are requested automatically when a PR touching their files is opened, and with the "require review from Code Owners" branch rule, their approval is mandatory.

.github/CODEOWNERS
*                      @shop/platform
/src/checkout/         @shop/payments
/infra/                @shop/sre @dana-ops
*.md                   @shop/docs

If nobody has responded within about a business day, a short, polite nudge is normal: "Hi Sam, could you look at #812 today or tomorrow? It is about 120 lines and blocks the payments release." Give the size and the reason. Google's guidance for reviewers is to respond within one business day, so a nudge after that is not pushy.

During the review

Treat every comment as something that needs an answer, even if the answer is "I disagree, because...". Receiving feedback without the ego covers the conversation itself. The mechanics are:

  • Reply to every thread. "Done in 3f2a9c1" with the commit hash lets the reviewer check your change in one click.
  • Push new commits, do not rewrite. GitHub can show a reviewer "changes since your last review", and that works best when you add commits. A force-push after a rebase makes reviewers re-read the whole thing. If you must rebase mid-review (say, to pick up a fix from main), say so, and git range-diff can show what changed between the old and new versions of the branch.
  • Use --fixup commits for changes that belong in an earlier commit, then squash them with git rebase -i --autosquash just before merging, if the team does not squash-merge anyway.
  • Re-request review when you have addressed everything. GitHub has a button for it; otherwise the reviewer may not know you are done.
  • Do not resolve someone else's question silently. Resolving a thread you started is fine. Resolving a reviewer's concern without a reply looks like hiding it.
Match the pairs0/5 matched

Match each situation to the best response.

Choose an item, then its match on the other side.

Merging, and after

On most teams the author merges once the PR is approved and checks pass, because the author knows when it is safe to ship. gh pr merge --squash --delete-branch (or the button) squashes, merges and removes the branch. With --auto, GitHub merges by itself once the required approvals and checks are in place, which is handy for a PR waiting on a slow test suite. Busy repos may use a merge queue instead, covered in Branching Strategies Teams Use.

Check the final commit message when squashing. GitHub fills it from the PR title and your commit messages, and a body full of "fix typo" and "address review" lines helps nobody. Edit it down to the description's "what and why".

Merging is not the end. Watch the deploy: check that the pipeline went through, look at the error tracker and the dashboards for the area you touched, and check the feature in production if you can. If something looks wrong, you are the person with the most context, and the rollback plan is already in your description. Then close the ticket and the follow-ups.

AI-assisted pull requests

Everything above applies with more force when an AI tool wrote part of the change, because AI makes it cheap to produce PRs that are too big to review. AI on a Real Team covers this in detail. The short version: keep the same size discipline, say in the description how the change was produced if your team expects it, and remember that you own every line. If you cannot explain a part of the diff to your reviewer, it is not ready.

A pull request from push to production
YouCIReviewermainpush branch, open PRchecks greenrequest reviewcommentsre-request reviewapprovesquash-merge, delete branch

Small, self-reviewed, with a description that covers what, why, testing and risk.

1/7
Key terms
pull request
A request to merge a branch, with a diff, a description, automatic checks and a review conversation. GitLab calls it a merge request.
draft PR
A pull request marked as not ready: open for early feedback on direction, but not mergeable and not auto-assigned to code owners.
stacked PRs
A chain of dependent pull requests where each targets the branch below it, so a large change is reviewed in small pieces.
CODEOWNERS
A file mapping path patterns to owners, who are requested automatically and can be made required reviewers. The last matching pattern wins.
self-review
Reading your own diff as a reviewer would before asking anyone, to catch debug code, stray files and unclear names.
rollback plan
How to undo a change if it misbehaves in production: a flag to turn off, a revert, or a migration to reverse.
auto-merge
A GitHub setting on a PR that merges it automatically once required reviews and checks pass.