Stage 5: Professional Skills

Git Collaboration · Lesson 03

Pull Request Review

Writing good pull requests, reviewing code and squash merging.

Git Collaboration3 min readFree lesson

A pull request is the unit of collaboration: a diff, a discussion, a CI result and a decision. Writing and reviewing them well is a skill hiring teams notice immediately.

Learning objectives

  • Open a pull request that a reviewer can understand in minutes.
  • Review code for correctness, clarity and risk.
  • Use squash merging without losing context.
  • Configure branch protection and required checks.

1. Before opening the PR

git switch main && git pull --ff-only
git switch feature/course-filters
git rebase main
npm test
git push -u origin feature/course-filters

A PR that does not build wastes the reviewer's first ten minutes.

2. Writing the description

## What
Adds level and mode filters to the course catalogue.

## Why
Visitors currently scroll through 40 courses. Filtering reduces time to
course selection and matches the filters already used on /locations.

## How
- URL state via `useSearchParams` (shareable links)
- Filtering happens client-side; the catalogue is 40 items
- Empty state added when no course matches

## Testing
- `npm test` — 42 passing
- Manual: /courses?level=beginner&mode=online
- Checked mobile at 360px

## Screenshots
(before / after)

The reviewer should not have to reconstruct the intent from the diff.

3. Keep the diff reviewable

  • Under ~400 changed lines is comfortable; 1,500 is a rubber stamp.
  • Separate refactors from behaviour changes.
  • Do not mix formatting with logic.
  • Delete dead code in its own commit.
  • Link the issue the PR closes: Closes #128.

4. Reviewing

Review in this order:

  1. Does it do what it claims? Read the description, then the tests.
  2. Correctness — edge cases, error paths, empty states, permissions.
  3. Security — user input, secrets, authorisation checks.
  4. Clarity — names, structure, comments where the "why" is non-obvious.
  5. Style — let the formatter and linter handle it; do not argue taste in review.

Comment types:

  • Blocking: "This allows an unauthenticated user to delete a course."
  • Question: "What happens when items is empty?"
  • Suggestion: "Could this reuse formatPrice from lib/money?"
  • Nit: "Typo: recieve → receive." — mark as non-blocking.

Approve when the change is safe to ship, not when it is perfect.

5. Responding to review

  • Push follow-up commits; do not force-push during an active review unless the team expects it.
  • Reply to every comment — "Done in abc123" or a reason.
  • If you disagree, explain the constraint and propose an alternative.
  • Resolve conversations only after the reviewer confirms.

6. Merging

Merge commit keeps every commit and the branch shape. Squash and merge turns the PR into one commit on main:

Add course filters (#128)

Squash is the default for most product teams: one logical change, one revertable commit, a clean main. Use merge commits when preserving the individual commits matters.

After merging:

git switch main
git pull --ff-only
git branch -d feature/course-filters

7. Branch protection

On GitHub: require a pull request before merging, require approvals, require status checks, require branches to be up to date, disallow force pushes. These settings turn good intentions into guarantees.

Common mistakes

  • A PR titled "fixes" with no description.
  • Reviewing 2,000 lines and approving because it is too late to read.
  • Force-pushing while reviewers are mid-review.
  • Merging with failing tests "to unblock" — that is how main becomes undeployable.
  • Leaving the branch undeleted and the issue open.

Practice

Complete the review exercise in the assignment: open a small PR, review someone else's, and merge with a squash commit.

Assignment

Assignment 03 — Pull request and review

Practise the full PR cycle on a test repository (yours, or a fork).

Part A — Open a pull request

  1. Create feature/readme-improvements from main.
  2. Make three small commits: fix a typo, add a "Getting started" section, add a screenshot.
  3. Push the branch and open a PR using the template:
## What
## Why
## How
## Testing
## Screenshots
  1. Link an issue with Closes #<number> (create one if needed).
  2. Add a reviewer.

Part B — Review

Review a partner's PR (or your own from a second account):

  1. Leave at least one blocking comment, one question and one nit.
  2. Check: does the description match the diff? Are there tests? Is any secret committed?
  3. Approve only after the blocking comment is resolved.

Part C — Merge

  1. Squash-merge the PR.
  2. Confirm main contains exactly one new commit with a clear message.
  3. Delete the remote and local branch.
  4. Run git log --oneline -5 and paste the result into the PR as a comment.

Part D — Protect the branch

Enable, on the test repository:

  • Require a pull request before merging
  • Require one approval
  • Require status checks (add a trivial CI workflow if none exists)
  • Disallow force pushes

Then try to push directly to main and record what happens.

Done when

  • The PR description explains what, why, how and how it was tested.
  • The squash commit on main references the PR number.
  • A direct push to main is rejected.

Learn this lesson with a mentor

Work through the Build Your Homepage series on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now