Computing Foundations › Git and GitHub › Day 33

Day 33: Pull Requests and Code Review

Day 33 of 365 — Pull Requests and Code Review

After this lesson you will be able to explain the pull-request and code-review workflow end to end — propose a change on a branch, open a PR, review and iterate, choose a merge strategy, and protect a branch — and rehearse the whole loop locally with plain Git.

Course
Computing Foundations
Category
Git and GitHub
Reading time
≈ 40 min
Practical time
≈ 30 min
Lesson duration
1h 10m
Last verified
2026-07-12

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-033-pull-requests-and-code-review

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
    cd labs/sections/computing-foundations/day-033-pull-requests-and-code-review
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters


The idea in plain language


Historical background

Diagram: the progression from mailed patches to hosted pull requests


What it is — and what it is not

It is:

It is not:


Why it was created and what problems it solves

Diagram: what automated checks should catch compared with what review is for


How it works

The lifecycle

Flowchart: the life of a pull request from branch to merge

What a reviewer actually sees

Diagram: a poor pull request description compared with a useful one

Diagram: the anatomy of a pull request page

ComponentWhat it does
Title and descriptionWhat the change does and why — the first thing read
DiffThe line-by-line comparison; the substance of the review
Inline commentsFeedback attached to specific lines, where it applies
ChecksBuilds, tests and linters, reporting before a human has to
Reviewers and stateWho was asked, and whether each approved or requested changes
Merge buttonEnabled only when the branch’s rules are satisfied

The sequence

  1. Branch from an up-to-date main: git switch -c fix-export-button.

  2. Commit one focused change with a clear message. One fix or one feature, not five unrelated things.

  3. Push and open, filling in a real title and description.

  4. Review. Teammates read the diff and comment; CI runs meanwhile.

  5. Iterate. Push more commits to the same branch. Each push updates the PR and re-runs the checks.

  6. Merge, choosing a strategy, and delete the branch.

Merge strategies

Diagram: the history produced by each merge strategy

StrategyWhat it doesHistoryBest when
Merge commitJoins the branch in, preserving every commitBranching, with a merge pointYou want the full record of how the branch developed
Squash and mergeCombines everything into one commitFlat and linear; one commit per PRThe intermediate commits are noise
Rebase and mergeReplays each commit onto mainLinear, preserving individual commitsYou want a straight line and value the steps

Protected branches

Diagram: the rules a protected branch enforces


An everyday analogy

Diagram: when to open a draft pull request

Submitting an article to an editor.

The publicationThe pull request
Your draftThe source branch
The published editionThe target branch
The submissionOpening the PR
The covering noteThe description
Margin notes on specific linesInline comments
The spell-checkerAutomated checks
”Approved” or “revise and resubmit”Review state
Going to printThe merge

Examples in practice

Diagram: a small pull request compared with a large one

Diagram: checks a machine can run compared with what human review is for


Implications: security, privacy, performance, scalability, and cost


Alternatives: free, open source, and commercial

ApproachTypeWhere it fits
Platform pull requestsFree tiers, commercialThe default for almost every team
gh / glab CLIFree, open sourceOpening and reviewing PRs without leaving the terminal
Email patchesFree, built into GitThe Linux kernel; genuinely scalable, with a steep entry cost
GerritFree, open sourceChange-by-change review, heavier and very rigorous
Pair programmingA practiceReview happening continuously instead of afterwards
Trunk-based with post-merge reviewA practiceSpeed over gating; needs strong tests and trust

TermWhat it actually is
Pull requestA proposal to merge one branch into another, with discussion
Source branchWhere your commits are
Target branchWhere you want them to end up
CheckAn automated build, test or lint run on the change
Protected branchOne that refuses direct pushes
ApprovalA reviewer’s recorded agreement
SquashCombining a branch’s commits into one on merge

When to use it — and when not to

Diagram: unhelpful review comments compared with useful ones


The AI connection

Diagram: what makes a machine learning change reviewable


Knowledge check

quiz:
  question: "A team notices that large pull requests consistently receive shorter, less useful reviews than small ones. What is the most effective response?"
  options:
    - "Split work into smaller pull requests, since review quality falls sharply with size"
    - "Require more approvers on large pull requests to increase total scrutiny"
    - "Extend the review deadline so reviewers have more time for large changes"
    - "Add more automated checks so reviewers can focus only on the largest files"
  answer_index: 0
  explanation: "Review attention does not scale with size — beyond a few hundred lines, reviewers skim regardless of how long they are given or how many of them there are. Making the unit of review smaller is the only change that reliably restores the depth of the review."

Hands-on exercise

Simulate the whole flow locally, then compare merge strategies. Worked through fully in the Day 33 lab directory.

What you are doingCommand
Branch and commitgit switch -c fix-export then commit
Review your own diffgit diff main...fix-export
See it as a reviewer wouldgit log main..fix-export --oneline
Merge preserving historygit switch main && git merge --no-ff fix-export
Try again, squashedon a second branch: git merge --squash then commit
Compare the two shapesgit log --oneline --graph --all
Open a real one, if you have a remotegh pr create --fill

Expected output

*   3f9a2c1 Merge branch 'fix-export'
|\
| * 8b1d4e7 Add test for Safari event listener
| * 2c7f0a9 Attach missing click handler
|/
* 1a0b9c8 Initial import
* 5d3e8f2 Squashed: fix export button on Safari

Validate your work

Troubleshooting

Common mistakes


Practice assignment


Extension challenge


Quiz

Q1. What is a pull request?

  1. A proposal to merge one branch into another, with review
  2. A Git command that instantly merges one branch into another
  3. A backup copy of the main branch kept on the remote
  4. A message that pulls the latest changes from the remote to your laptop
Show answer

Answer: A. A proposal to merge one branch into another, with review

A pull request is a proposal to integrate a branch, layered with a diff, discussion, checks, and approvals. Git itself has no pull-request command; hosting platforms build the feature on top of Git branches and merges.

Q2. GitHub calls it a "pull request." What does GitLab call the same workflow?

  1. A push request
  2. A merge request
  3. A branch review
  4. A commit proposal
Show answer

Answer: B. A merge request

GitLab uses the name "merge request" (MR) for the identical workflow. The two terms describe the same branch-based, reviewed-then-merged process.

Q3. Why are small, focused pull requests generally better than large ones?

  1. They use less disk space on the remote server
  2. Git refuses to merge pull requests above a certain size
  3. They are read carefully; large PRs get shallow reviews
  4. They automatically skip the review step
Show answer

Answer: C. They are read carefully; large PRs get shallow reviews

A small PR touching one concern can be reviewed thoroughly in minutes; a large PR mixing many changes buries the important lines and pushes reviewers toward rubber-stamping, which defeats the purpose of review.

Q4. A reviewer sets their state to "request changes" on your pull request. What does this mean?

  1. The pull request is rejected and must be closed and reopened
  2. Continuous integration has failed
  3. The change has been merged with modifications
  4. The reviewer is blocking the merge until you address it
Show answer

Answer: D. The reviewer is blocking the merge until you address it

Requesting changes blocks the merge until the feedback is addressed, but it is ordinary iteration, not rejection. You push more commits to the same branch, the PR updates, and the reviewer re-reviews.

Q5. Which merge strategy combines all of a branch's commits into a single new commit on main?

  1. Squash and merge
  2. Rebase and merge
  3. Merge commit
  4. Fast-forward merge
Show answer

Answer: A. Squash and merge

Squash and merge collapses every commit on the branch into one commit on main, producing a flat history where each pull request is a single, revertible unit. The intermediate commits are discarded.

Q6. What does protecting the main branch accomplish?

  1. It encrypts the branch so only administrators can read it
  2. It refuses direct pushes and forces changes through a PR
  3. It makes the branch read-only forever
  4. It automatically backs up every commit to a second server
Show answer

Answer: B. It refuses direct pushes and forces changes through a PR

A protected branch cannot be pushed to directly; the only way in is a pull request that satisfies rules such as required approvals and passing checks. This is what lets a team trust that main is always in a releasable state.

Q7. What are CI checks on a pull request?

  1. Comments left by senior reviewers
  2. A manual checklist the author fills in by hand
  3. Automated builds, tests, and linters run on the change
  4. The list of files the pull request modifies
Show answer

Answer: C. Automated builds, tests, and linters run on the change

Continuous-integration checks run automatically on every push to the pull request, building the code and running tests and linters. Their green or red status is one of the gates a protected branch can require before merging.

Q8. Which of the following belongs in a good pull-request description?

  1. Nothing — the diff speaks for itself
  2. The reviewer's home address so they can be reached quickly
  3. A copy of every command you typed while working
  4. What the change does, why it is needed, and how it was verified
Show answer

Answer: D. What the change does, why it is needed, and how it was verified

A strong description states what changed, the reason for the change, and how the author confirmed it works. It lets a reviewer understand intent quickly instead of reverse-engineering it from the diff, and it becomes a permanent record of why the change was made.

Glossary

pull request
A formal proposal to merge the commits on one branch into another, presented with a diff, a description, a review discussion, and merge gates; abbreviated PR.
merge request
GitLab's name for a pull request — the identical branch-based, reviewed-then-merged workflow; abbreviated MR.
code review
The practice of having one or more people read a proposed change before it is merged, to catch bugs, share knowledge, and improve design.
diff
The line-by-line comparison between two versions of the code, showing exactly which lines a change adds, removes, and modifies.
approval
A reviewer's recorded verdict that a pull request is good enough to merge; protected branches can require one or more approvals before the merge button unlocks.
request changes
A reviewer's verdict that formally blocks the merge until the author addresses specific feedback; a normal step in iteration, not a rejection.
squash merge
A merge strategy that combines all of a branch's commits into a single new commit on the target branch, producing a flat, one-commit-per-pull-request history.
protected branch
A branch the hosting platform refuses to let anyone push to directly; changes may enter it only through a pull request that satisfies its rules.
CI check
A continuous-integration check — an automated build, test, or linter that runs on a pull request and reports pass or fail before a human reviews the change.
reviewer
A person asked to read a pull request and record a verdict — approve, comment, or request changes — on whether it should be merged.
draft pull request
A pull request marked as work-in-progress to signal it is not yet ready for formal review or merge; it is opened for review by marking it ready.
merge commit
A commit with two parents that joins a branch back into the target branch, preserving the branch's individual commits and recording where the merge happened.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.