Git & GitHub ยท Chapter 31 of 42

Code Review Basics

Code review is the practice of having other developers examine your changes before they're merged, usually through a GitHub pull request. It catches bugs, improves code quality, and shares knowledge across a team.

Good code review involves clear, respectful comments, focusing on the code rather than the person, and asking questions when something isn't clear instead of assuming the worst.

Syntax
# On GitHub PR page:
# Click a line number to comment
# Use 'Request changes' or 'Approve'

Giving good feedback

Comment on specific lines, explain the reasoning behind suggestions, distinguish between required changes and optional suggestions, and acknowledge good decisions too.

Responding to feedback

Treat review comments as helpful, not personal criticism. Reply to clarify decisions, make requested changes, and push new commits to update the same pull request.

Example 1 (bash)
git add app.js
git commit -m "Address review feedback: validate empty input"
git push
Output
[main 7f3c2ee] Address review feedback: validate empty input

Commits and pushes a fix in response to a reviewer's comment, updating the same pull request automatically.

Example 2 (bash)
git log --oneline -3
Output
7f3c2ee Address review feedback: validate empty input
9c2e1aa Fix crash when cart is empty
a3f5c9e Add login validation

Shows the review-driven follow-up commit in the branch's history.

Key points

  • Code review has other developers examine changes before merging.
  • It catches bugs and spreads knowledge across the team.
  • Feedback should focus on the code, not the person.
  • Pushing new commits to the same branch updates an open pull request.
๐Ÿ’ก Note: Small, focused pull requests are much easier and faster to review than huge ones.

๐Ÿ“ Quick Quiz

1. What is the main purpose of code review?

2. Good review feedback should focus on:

3. What happens when you push new commits to a branch with an open PR?