How to Code Review Using GitHub
Introduction
Git and GitHub have become mainstream in the industry, and there is a high chance that your project will also use them for version control. This article mainly explores the many built-in features on the GitHub web version that can enhance code review efficiency and are worth understanding.
Since GitHub is a service built on top of Git, we often underestimate its functionalities. However, GitHub has many great features that are not so obvious, so I will share some that I find useful but are often overlooked in daily use.
Tip 1: Submission Review Methods
Have you ever wondered what the difference is between “Add single comment” and “Start a review” during a GitHub review? If you haven’t specifically checked the documentation, you might not know the difference in purpose between these two buttons. Aren’t they both for submitting reviews?
The main difference lies in the usage scenario. If you are sure that you only have one review to submit, then “Add single comment” is very convenient. However, if you have multiple reviews to submit, it’s better to choose “Start a review” so you can comment all at once before submitting.
- Add single comment: Quickly submit a single comment.
- Start a review: Add multiple comments and click the “Finish your review” button to submit them all at once.
Why not submit one by one? Because each submission will notify (and even email) everyone watching the PR. If there are many items to review or it takes a long time, frequent notifications can be quite annoying.
Tip 2: Code Suggestions
Sometimes you want to provide some code suggestions during the review, and you can use the “Add a suggestion” feature (or ctrl + g
). This will bring up a Markdown Code Block, making it easy to write down suggestions, and when switching to Preview, it will automatically show an interactive comparison with the existing code.
Reviewers, while reading the review, not only receive more specific suggestions but can also directly click the “Commit suggestion > Commit changes” button to apply the suggestions.
Tip 3: Multi-line Review
The ”+” button to activate code suggestions is actually draggable, allowing you to select multiple lines of related code for review at once.