Skip to content
Back to log

How to write a good PR description

Chainabit's Chao · · 7 min read

In short

GitHub shows the pull request description as part of the review context. Google's CL guide provides criteria for the first line, rationale, labels, and clarity for future readers.

According to GitHub, a pull request is a proposal to merge code changes into a project. Teams can discuss and review the changes on the pull request before merging them. The description appears in GitHub's Conversation tab alongside the timeline, comments, and reviews.

Google's CL description guide provides description criteria for a CL, which means change list. Google defines the CL description as a public record of the change. This record should explain what changed and why the change was made. The first-line, body, and label criteria below come from Google's CL guide.

The first line of a CL description

According to Google, the first line should briefly and concretely summarize the work done in the CL. It should be followed by a blank line. The first line also appears in summaries of version control history. It therefore needs to make sense independently of the rest of the description.

Google's criterion is that someone searching for code in the history should not have to read the CL itself or the entire description to understand what the change does or how it differs from other CLs. While asking for the first line to be kept short and focused, Google prioritizes clarity and usefulness for the reader.

According to the convention Google describes, the first line should be a complete sentence written in the imperative mood. When describing the deletion of an RPC and its replacement with another system, the guide gives an example sentence that expresses the work done in the imperative. The rest of the description does not have to be written in the same mood.

Which first lines fall short?

Google gives “Fix bug” as an inadequate CL description. The phrase does not specify which bug was addressed or what was done to fix it. Other phrases Google places in the same group include “Fix build”, “Add patch”, and “Phase 1”.

“Moving code from A to B”, “Add convenience functions”, and “kill weird URLs” are also among Google's inadequate examples. Google states that although these descriptions are short, they do not provide enough useful information. Some of the examples in the guide are real CL descriptions.

The change's context in the body

According to Google, the section after the first line should contain the details needed to understand the CL as a whole. This section can include a brief description of the problem being solved and the rationale for the chosen approach. If the approach has shortcomings, these should also be stated.

Google also asks authors to describe the context they had when making the change and the decisions that are not visible in the code. Code can show what the software does, but it may not reveal why it exists. Google states that this can make it harder for future developers to understand whether they can change the relevant code.

When relevant, bug numbers, benchmark results, and design links can also be added to the body of the description. Google notes that external links may not be visible to future readers because of access restrictions or retention policies. Whenever possible, it asks for the description to contain enough context for reviewers and future readers to understand the CL.

According to Google, small CLs also deserve attention to detail and context. In the guide's example of a small change, the first sentence states the work done. The explanation that follows gives the reason for the change and the context the reviewer needs.

Google's description examples

Google's example of a functionality change concerns an RPC server message freelist. The first line says that the size limit on the freelist has been removed. The section that follows explains that some servers use large messages and could benefit from reusing them.

The example description also explains that the freelist is enlarged and a goroutine is added to slowly free entries over time. This allows freelist entries on idle servers to be freed over time. Google states that the first words of the example describe the work done, while the rest explains the problem, the rationale for the solution, and some of the implementation details.

In the refactoring example, the first line describes constructing a Task with a TimeKeeper to use the TimeStr and Now methods. The body explains the addition of a Now method to Task and how the borglet() getter method can be removed. According to the example, the getter was used only by OOMCandidate to call borglet's Now method.

Turn this insight into action.

Use the mobile app to continue with guided workflows.

The same description states that having Tasks provide Now is a step toward removing the Borglet dependency. Having components that get Now through Task use TimeKeeper directly in the future is described as a possible direction. Google says the example also explains that the current solution is not ideal and accommodates refactoring in small steps.

In the small CL example, a build rule is created for status.py. The description explains that users of the relevant file can depend on the rule next to the original status build rule instead of a rule located elsewhere in their tree. Google presents this as an example of how even a small change can carry the reason and review context.

The description's place in code history

According to Google, the CL description is a permanent part of version control history. Future developers may search for a CL by its description. The person searching may vaguely remember that the change was relevant without remembering its details.

Google states that when all the important information is in the code and absent from the description, finding the relevant CL becomes harder. Once the CL is found, it is also necessary to understand why the change was made. The guide assigns the description two tasks: summarizing the main changes made and explaining their rationale.

The summary of the main changes should give the reader an idea of what changed without reading the entire CL. The rationale can include the circumstances the author knew about when making the change and decisions that the code does not reflect. Google frames this distinction through two questions the CL description should answer: What is changing and why is it changing?

The place of labels

Google defines labels as markers entered manually to classify CLs. Tools may support them, or teams may use them under their own rules. In Google's guide, using labels is optional.

Labels can appear in the first line, within the text, or elsewhere in the description. Google asks for limited use of labels in the first line because they can obscure the main content. The guide's examples also accept multiple labels in the first line when they are kept short.

In Google's counterexample, long labels dominate the main description in the first line. The guide discusses moving the labels to the body of the description or shortening them in this case. In a separate example, labels appear in a section after the descriptive sentence.

What appears alongside the description on GitHub

According to GitHub, a pull request brings together the context reviewers need to understand a change in tabs. The Conversation tab contains the description, timeline, comments, and reviews. The Commits tab shows how the pull request branch has changed over time.

The Checks tab shows automated tests, build processes, and other validations. The diff in the Files changed tab is the view reviewers use to understand the proposed changes. The Findings tab contains automated code review results for the proposed changes; GitHub gives code scanning alerts as an example.

The merge status appears separately from the tabs. According to GitHub, this area highlights blockers, missing approvals, and other requirements before merging. It appears in the pull request header and in the merge box. GitHub states that these views help authors and reviewers discuss the change, track feedback, and decide whether it is ready to merge.

Before review and limitations

Google states that CLs can change significantly during review. Rereading the description before submitting the CL is a step in the guide to see whether the text still reflects the work done.

For CLs created with tools, Google also asks for the same description structure whenever possible. The first line should be short, focused, and meaningful on its own. The body should contain details that help reviewers and people searching the code history later understand the CL's impact.

In Google's approach, a short phrase alone is not considered sufficient: “Fix bug” does not explain which bug was fixed or what was done. External links may also be unavailable to future readers because of access restrictions or retention policies. To address this limitation, Google asks for the necessary context to be included in the CL description whenever possible.

Ready to start?

Download the app and continue from your phone.

End of Entry