Sub topic 4
Writing a good description and using templates
This chapter assumes you can open a pull request from a feature branch and know what a diff is. A pull request description is the first thing a reviewer reads. It tells them what to look for and how to judge the change.
What a description must answer
The diff shows what changed line by line. The description covers what the diff cannot show:
- What changed: a one or two sentence summary in plain words.
- Why: the problem, or a link to the issue.
- How to test: steps a reviewer can follow to see the change work.
- Risks and scope: what you deliberately left out, and anything that needs a careful look.
A common error is repeating the diff ("Changed timeout from 10 to 30"). Say why instead: "Slow networks hit the 10s limit and users saw spurious login failures."
Titles
Write the title as a short statement of the result, in the same style as your commit messages. "Increase login request timeout" is searchable and clear. "Fixes" and "Update stuff" are not. If the pull request is squash merged, the title often becomes the commit message on the main branch, so it matters beyond the review.
Linking issues
Closing keywords connect a pull request to an issue. Write Closes #42, Fixes #42, or Resolves #42 in the description. When the pull request merges into the default branch, GitHub closes the issue automatically. Use a plain reference such as Related to #42 if the issue should stay open.
Templates
A pull request template pre-fills the description of every new pull request in the repository. Save it as .github/pull_request_template.md on the default branch.
## What changed
<!-- One or two sentences on the change -->
## Why
<!-- Link the issue or describe the problem -->
## How to test
<!-- Steps a reviewer can follow -->
## Checklist
- [ ] Tests added or updated
- [ ] Documentation updatedThe <!-- --> lines are comments. They are hidden when the description is displayed, so replace them with your own text. The checklist items become clickable checkboxes.
A repository can also keep several templates in a .github/PULL_REQUEST_TEMPLATE/ directory. GitHub does not choose among them for you. You pick one by adding ?template=name.md to the pull request URL.
Keeping the description current
The description is not frozen when you open the pull request. If review changes the approach, edit the description so it matches the final change. Reviewers who arrive late read the description first, and a stale one misleads them.
gh pr create --draft --fill
gh pr edit --body-file notes.md--fill takes the title and body from your commits. It gives a quick start, but you should still add the why and the test steps.
Exercise
Your pull request fixes issue 57, but you want the issue to stay open until a follow-up ships. Which wording do you use in the description, and why?
Show answer
Use a non-closing reference such as "Related to #57". Closing keywords like "Closes #57" would close the issue automatically when the pull request merges into the default branch.