skip to content

What is a suggested change in a GitHub pull request review, and how does it reach the branch?

level: middleimportance: should knowfreq 52%

answer

  1. A specially tagged fenced block
  2. Replaces the exact lines you commented on
  3. Author accepts it with one click
  4. It lands as a real commit
  5. Credit is preserved via a trailer

basics

~20 s

A suggested change is a review comment containing a fenced suggestion block with replacement lines. Anyone with write access to the pull request's branch can apply it in one click, creating a commit on that branch that credits the reviewer as co-author.

solid answer

~50 s

In a GitHub review comment you can wrap replacement lines in a fenced block tagged `suggestion`. GitHub renders it as a diff against the lines you commented on, and shows the author a **Commit suggestion** button — or **Add suggestion to batch**, which collects several and commits them together. Applying one creates a real commit on the pull request's head branch, with the reviewer recorded as **co-author**, so credit and blame stay honest. That commit triggers the pull request's checks like any other push. The constraints are worth knowing. A suggestion can only target lines present in the diff you are commenting on, it can span a selected range of lines, and it cannot be applied if the underlying lines have since changed — the comment goes outdated and the button disappears. Applying also requires write access to the head branch, which for a fork-based pull request means the fork, not your repository.

code

markdown · 5 lines
markdown
This drops the last element when `end` is inclusive.

```suggestion
    return items.subList(start, end + 1)
```

go deeper

for a junior

Know how to write one: a fenced block tagged suggestion containing the exact replacement lines at the right indentation, anchored to lines in the diff.

for a middle

Explain what happens on accept — a commit on the head branch, reviewer recorded as co-author, checks re-run — and name the constraints: diff lines only, outdated once the region changes, write access to the head branch required.

for a senior

Show taste in when to use one: unambiguous small edits yes, design disagreements no. Mention batching to avoid commit and CI churn, and the risk of suggesting code you have not compiled.

for a principal

Own the norm across teams: suggestions are for mechanical fixes, and a pull request attracting dozens of them is a signal about tooling gaps or pull request size, not something to solve one click at a time.

## The mechanism A **suggested change** is an ordinary review comment whose body contains a fenced code block tagged `suggestion`. The content of that block is the proposed replacement for the lines the comment is anchored to. GitHub renders it as a small diff and offers the pull request author — or anyone with write access to the head branch — a button to apply it. Because the suggestion replaces the commented range wholesale, the block must contain the complete replacement text, at the correct indentation, and nothing else: no prose, no diff markers. An empty suggestion block deletes the lines. Comment on multiple lines by dragging over a line range in the diff, and the suggestion replaces the whole range, which is how you propose a three-line rewrite rather than a one-liner. ## What applying it does Clicking **Commit suggestion** creates a commit on the pull request's head branch. The commit message can be edited, and GitHub records the suggesting reviewer as a **co-author** in the commit trailer, so `git log` and blame show that the change came from the review. Because it is a genuine push, it re-triggers the pull request's checks and behaves exactly like any other commit for rules that dismiss stale approvals. When several suggestions are outstanding, **Add suggestion to batch** on each and then commit them together produces one commit and one CI run rather than a run per click — the difference between a tidy history with one pipeline execution and eight commits called "Update foo.kt" with eight builds behind them. ## Where suggestions cannot be used **Only inside the diff.** You can anchor a comment to lines shown in the pull request's diff. A fix that belongs in a file the pull request does not touch cannot be a suggestion; it has to be described in words. **Not once the lines move.** If the author pushes commits that change the region, the comment becomes **outdated**, the suggestion no longer applies cleanly, and the button goes away. Long-lived suggestions on an actively-pushed branch simply evaporate. **Write access to the head branch is required.** For a pull request from a fork, the head branch lives in the contributor's repository. Maintainers can apply suggestions there only when the contributor left "allow edits by maintainers" enabled; otherwise the contributor applies them. **Not for structural change.** A suggestion is a textual replacement of a contiguous range. Renaming a symbol across five files, extracting a function, or reordering declarations is not expressible as one, and squeezing it into a suggestion produces something that compiles in the reviewer's head and not on the branch. ## Why they are worth using Suggestions collapse the slowest loop in review. The alternative to "here is the exact line, click to accept" is: reviewer writes a sentence describing a change, author interprets it, pushes something slightly different, reviewer re-reads, and two days pass over a variable name. For small, unambiguous edits — a typo, an off-by-one boundary, a missing null guard, a clearer name — the suggestion is faster, unambiguous, and reviewable as a diff before it is accepted. They also change the tone of review. "This is wrong" invites defence; a concrete suggestion the author can accept, modify, or reject with a reason is a proposal, and proposals get discussed on their merits. ## Where they are misused Three failure modes recur. **Suggestion storms**: forty single-line suggestions on a pull request where the real feedback is that the approach is wrong — batch them or, better, write the one comment that matters. **Untested suggestions**: a snippet typed into a text box has never been compiled, and applying it can leave the branch broken until CI says so; keep them small enough that you are certain. **Suggestions as a substitute for a conversation**: when the change is a design decision, the author needs the reasoning, not a patch to click. ## The habit worth forming If your comment tells the author exactly what to type, make it a suggestion instead. If your comment is asking them to think, leave it as prose.

  • Why prefer "Add suggestion to batch" over committing each suggestion individually?
    Each individual commit is a separate push, so eight suggestions become eight commits and eight CI runs, cluttering history and burning runner time. Batching collects the accepted suggestions and lands them as one commit with a single pipeline run, which also keeps the pull request timeline readable when someone later reconstructs what review changed.
  • When does a GitHub suggestion stop being applicable?
    When the lines it targets change. Pushing commits that touch that region marks the review comment outdated, the suggestion no longer applies cleanly, and the apply button disappears; the comment stays in the timeline as history. Suggestions are also unavailable on lines outside the diff, and on a fork-based pull request a maintainer can only apply them if the contributor allowed maintainer edits.
  • What kinds of feedback should not be delivered as a suggestion?
    Anything structural or debatable. A suggestion is a textual replacement of a contiguous range, so cross-file renames, extractions and reorderings do not fit. Design disagreements should not be a patch either — the author needs the reasoning to evaluate it, and a click-to-accept button on an architectural change pressures agreement without discussion.

saying these in an interview costs you the question

  • Thinks suggestions apply without creating a commit
  • Believes suggestions work on untouched files
  • Expects applied suggestions to skip CI checks
  • Sends dozens of one-line suggestions instead of one comment
  • Assumes maintainers can always edit a fork's branch

context