Sub topic 3
Writing a Pull Request Template
This chapter assumes you know how to open a pull request, edit Markdown, and commit files to a repository's default branch. You also need write access to a repository where you can experiment.
What a pull request template does
A pull request template is a Markdown file that GitHub copies into the description box of every new pull request. The author edits the text instead of starting from a blank box. The template does not enforce anything. It prompts the author, and reviewers get the same structure every time.
Create the file
Save the template as .github/pull_request_template.md on the default branch. GitHub also accepts pull_request_template.md in the repository root or in a docs/ folder. The filename is case-insensitive. The .github folder is the usual choice because it keeps the root uncluttered.
Here is a complete template:
## Summary
<!-- What does this change do, and why? -->
## Related issues
Closes #
## How was this tested?
- [ ] Unit tests added or updated
- [ ] Tested manually
## Checklist
- [ ] Documentation updated
- [ ] No breaking changes, or they are described aboveCommit it to the default branch. Pull requests opened after that point start with this text.
How each part works
- Headings give the author labeled places to write. Keep them short and use the same level throughout.
- HTML comments such as
<!-- What does this change do, and why? -->are visible in the editor but hidden in the rendered pull request. Use them for instructions that should not clutter the final description. Closes #uses a closing keyword. When the author adds an issue number (for exampleCloses #42) and the pull request merges into the default branch, GitHub closes that issue automatically.- Task list items (
- [ ]) render as checkboxes. Authors tick them in the description. GitHub shows progress, such as "1 of 2 tasks", on the pull request.
What the author sees
The author can still delete or rewrite any part of the text. If a section does not apply, the author can write "N/A" or remove it.
Common mistakes
- Putting the file on the wrong branch. The template must be on the default branch.
- Using the wrong path or name.
.github/PULL_REQUEST_TEMPLATE.mdworks, but.github/templates/pull_request_template.mddoes not. - Expecting enforcement. Checkboxes can stay unticked and sections can stay empty. If you need to block merges, use branch protection rules or a CI check that reads the description.
- Writing too much. A long template gets deleted wholesale. Aim for four or five sections that reviewers actually use.
- Using a file extension GitHub does not read. Use
.md(or.txt). Other formats are ignored.
Try it
- In a test repository, create
.github/pull_request_template.mdwith the example above. - Commit it directly to the default branch.
- Create a new branch, change any file, and push.
- Open a pull request. The description box should already contain your template.
If the box is empty, check the file path and confirm the commit landed on the default branch.
Exercise
You committed .github/pull_request_template.md to a branch named add-template and opened a pull request from that branch. The description box is empty. Why, and how do you fix it?
Show answer
GitHub reads templates only from the default branch. The file exists only on add-template, so it is not applied. Merge the branch into the default branch, then open a new pull request. The new pull request will be pre-filled. Pull requests that already exist are not updated.
Exercise
A reviewer wants every pull request to link an issue, and wants GitHub to close that issue on merge. Which line in the template does this, and what must the author do?
Show answer
The line Closes # under "Related issues". The author adds the issue number after it, for example Closes #42. When the pull request merges into the default branch, GitHub closes issue 42.