6 Best Practices to Review Pull Requests in GitHub
Code review is an integral part of the software development process. It helps ensure that code is efficient, secure, and maintainable.
Pull requests in GitHub are an effective way to manage code reviews. But bad pull requests slow down the development cycle and lead to low code quality.
Therefore, following certain pull request practices is essential to ensure proper collaboration and create a robust review culture. Below, we explain these practices.
🧐 How to accept pull requests in GitHub?
Here are the steps to accept a pull request in Github:
- Click Pull Requests under your repository name.
- Choose the pull request you want to review.
- Click the Files Changed icon on the pull request.
- Review the changes and add comments.
- After you've made the changes, click Review Changes to see the overall difference. You can also type a comment to summarize your feedback on the changes.
- Click on Approve to merge the changes in the pull request.
- Finally, click Submit Review.
You can also allow push requests in GitHub from the Pull Requests tab. Select Allow Edits from Maintainers in the user-owned forks under Pull Requests if you want to give everyone push access. If you're wondering, "How do I create pull requests in GitHub?" you can read more about it here.
👀 6 best practices to review pull requests in GitHub:
Here are six best practices for managing and reviewing pull requests in Github.
1️⃣. Create a pull request description and title
Before the reviewer dives into 800 lines of code, they should understand what they're reviewing. A good description or title can help with that and also set the proper context for the review. Here are the three things to include in a pull request description:
- Which task is this pull request accomplishing?
- How does this pull request accomplish the above task?
- Why was this approach taken? Do other approaches have impediments?
You can add videos and images if the code evaluations are related to user interface changes. For example, you can share a gif or picture of the working interface. Likewise, if there's complicated logic, use a sequence diagram to assist the reviewer in comprehending the changes.
You can use pull request templates, such as testing plans or impact. A template helps reviewers understand the changes and evaluate their impact on the codebase.
2️⃣. Include the files that need reviewing in the pull request
It's important to remember that not all changes are related to code. Other things, like documentation and configuration files, should also be included in the pull request. It gives clarity to the reviewer and provides a list of files they need to review before submitting their response.
3️⃣. Leave your ego out of it
You may get caught up in the details as a senior developer or reviewer and start nitpicking. That doesn't help the development cycle.
Try not to be too opinionated and focus on the bigger picture. The goal should be to find a solution that works for everyone and helps improve the codebase.
Give reasons for whatever you suggest. For instance, you can link to docs or articles that explain why your suggestion is better.
4️⃣. Leave comments and questions
It's essential to communicate with the author during reviews. Leave comments if you have questions or want to know more about a particular change. You can also use this opportunity to explain why you like something.
5️⃣. Avoid merging too soon
Just because you know how to merge pull requests in GitHub doesn't mean you should do it as soon as possible. The merge button should only be used once the reviewers test and accept the code.
Keep the pull request open until all questions and comments have been addressed. Again, direct communication is vital when it comes to reviews.
6️⃣. Keep it small
The more lines of code that need to be reviewed, the more time it will take. To make things easier for the reviewer, keep pull requests small and focused on a single feature or bug.
Break down large tasks into smaller pull requests and merge them after reviewing them. It takes a lot of time to compare pull requests in GitHub, especially when the changes are big.
It also increases the likelihood of the reviewer overlooking something. So, ideally, keep the lines of code under 500.
❤️ Automate your GitHub pull requests to save time with Mergify
Managing pull requests is time-consuming and tedious. There's a lot to do, from assigning reviewers to rebasing your branches.
Thanks to Mergify, you can automate most of these processes. Mergify's bot will update the pull request status, send you notifications of its real-time progress, and merge pull requests. Request a demo to learn how you can automate your code merge.