Wait! You Guys Have a PR Template?
As a developer, you know that interacting with pull requests is something we do daily as a regular activity. You can say that normal people breathe air, but developers breathe pull requests. Like air might contain harmful gases to a person’s lungs, pull requests might be created in a way that causes real pain to the other developers in your team and kills their productivity. One of the things that helps you create a good PR and saves your team from going through this pain is having a unified PR template.
What is a PR template?
A PR template is simply a template for the PR! Self-explanatory right? I know you didn’t come to hear this only, so let’s explain more.
A PR template is a template you can create and add to your Git repository, and it will be injected automatically into the description of any new PR you open. This allows your team to easily populate this template with any information you agreed on that might be helpful to understand and review the PR correctly. This information could be something like:
- A two to three lines paragraph that summarizes your work in the PR.
- A list of the changes you have done in simple words to prepare the reviewer for the code review.
- A checklist representing the standards that must be followed before merging the PR.
The information to include in the template is flexible, and you can add whatever you see as better for your team’s needs.
Now it’s time to create a template and see how it works. I chose to do this on GitHub as a matter of preference, but you can easily find and apply the equivalent to other Git tools after reading this.
How to create a GitHub PR template?
The first time I saw a PR template feature was a year and a half ago. A teammate added that template to our GitHub repository to standardize our pull requests, and I was like, wait! You guys have this feature?
For some reason, till now, I keep discovering hidden features in GitHub by coincidence. Despite the simplicity of that feature, it really did the trick.
To add the PR template to your repository, you need to create the .github
folder in the root of your repository and add the pull_request_template.md
file to it.
.
└── .github
└── pull_request_template.md
Then you can add whatever sections you want to your PR template. It could be something like this:
## Summary
<!-- Add a short paragraph that summarizes your work in the PR -->
## List of Changes
<!-- Add the list of changes without mentioning too much details -->
- Change 1.
- Change 2.
- Change 3.
## Checklist
<!-- Apply the checklist items before asking for review -->
- [ ] I tested my solution locally.
- [ ] I checked if my solution impacts other solutions.
- [ ] I wrote unit tests.
After pushing this to your main branch and creating new branches, any pull request you open will show that PR template in its description text area.
You can test this by forking the pull-request-template public repository I created with all its branches and trying to open a pull request from feat/update-readme
to main
and see what’s going to happen.
Finally, you should know that you don’t have to waste time creating the perfect PR template. You can start with a simple one and enhance it iteratively. Gradually it will become solid and fit your needs.
These are also good resources that can help you create your PR template: