Pull Requests and Code Review
6 learning objectives · 10 key terms · 7 commands · 3 diagrams · 5 quiz questions
Pull Requests and Code Review
CollaborationWhat you'll be able to do
- Explain what a pull request is and why it is more than a merge button
- Open a pull request with a title and description a reviewer can act on
- Use drafts, reviewers, labels and linked issues properly
- Review someone else’s change file by file and leave actionable comments
- Understand approve, request changes, and resolve conversation
- Choose between merge commit, squash and rebase merge — and know what each does to history
The idea, in plain language
A pull request is a proposal to merge one branch into another, wrapped in everything a team needs to decide whether it should. GitHub shows the exact difference the merge would introduce, runs your automated checks against it, gives reviewers a place to comment on specific lines, and keeps every reply, approval and decision attached to the change forever. The merge itself is the last thirty seconds; the value is everything that happened before it, especially the review comments that stopped a bug from reaching main.
Write the description as if the reviewer knows the codebase but not your change. Say what problem you are solving, what approach you took, what you deliberately did not do, and how you tested it. Link the issue it closes so the tracker stays honest. Keep the diff small — a reviewer can genuinely review 200 lines and will genuinely rubber-stamp 2,000. If a change has to be large, split it into stacked pull requests or land the mechanical part first (a rename, a formatting pass) and the behavioural part after, so the second diff is readable.
Active review is where quality comes from. Read the change the way you would read it for the tenth time: does the logic handle the empty case, the error path, the second call? Comment on the code rather than the author, ask questions instead of issuing verdicts, and distinguish blockers from suggestions ("nit:"). If your own pull request comes back with requested changes, that is the system working: push more commits to the same branch and the request updates itself.
Key terms
- Pull request (PR)
- A request to merge one branch into another, with review, discussion and automated checks attached.
- Draft pull request
- A pull request explicitly marked as not ready for review — it will not request reviewers.
- Diff
- The set of line-level changes the merge would introduce.
- Reviewer
- A person asked to examine and formally approve or block the change.
- Approve / Request changes
- The two formal review verdicts; "request changes" blocks merging when branch protection requires approval.
- Conversation
- A comment thread on a line or block; resolving it signals the point is settled.
- Squash and merge
- Combines every commit on the branch into one commit on main.
- Rebase and merge
- Replays the branch commits onto main individually, with no merge commit.
- CODEOWNERS
- A file mapping paths to required reviewers, so the right people are requested automatically.
- Closes #12
- A keyword in the description that closes the linked issue automatically when the pull request merges.
How it works, step by step
- 1Push the branch, then open the pull request
GitHub offers a "Compare & pull request" button as soon as a branch is pushed. Open it early — even as a draft — so the team can see the direction you are taking.
push firstbashgit push -u origin feature/login
- 2Write a title that summarises the change
The title becomes the merge commit subjects and the line in the release notes. Aim for the same standard as a good commit subject: imperative, specific, under about 60 characters.
- 3Write a description with four headings
What and why, how you verified it, anything a reviewer should watch out for, and the linked issue. Templates make this automatic — a .github/pull_request_template.md renders as the starting body.
description templatebash## What Adds session-based login with a 30-minute idle timeout. ## Why Closes #128 — users were being logged out mid-form. ## How I verified it Manual: login, idle 31 minutes, form submitted successfully. Tests: npm test (48 passing). ## Reviewer notes Auth middleware is unchanged; only the cookie lifetime moved.
- 4Target the right base branch and request reviewers
Base is the branch you want to merge into — usually main, but a release branch during a freeze. Request the people who know that area; CODEOWNERS can do it for you.
- 5Respond to review without opening a new pull request
Push more commits to the same branch. The pull request picks them up, keeps the discussion, and re-runs checks. Reply to each comment and resolve the thread when it is handled.
iteratebashgit add login.js git commit -m "Extend idle timeout to 30 minutes" git push
- 6Merge deliberately, then tidy up
Choose the merge method on purpose. Squash and merge is the common default for feature branches because it keeps main readable; a merge commit preserves the branch’s individual commits; rebase and merge gives linear history without a merge commit. Then delete the branch.
Commands worth memorising
Every block below is copy-ready — use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what “working” looks like.
git push -u origin feature/login
branch 'feature/login' set up to track 'origin/feature/login'.
-u is needed once per branch and is what makes a bare git push work afterwards.
gh pr create --base main --title "Extend session idle timeout" --body "Closes #128"
https://github.com/ada/app/pull/231
The closing keyword links the issue, which then closes automatically when the pull request merges.
git diff main...HEAD --statauth/session.py | 6 +++--- tests/test_session.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-)
The three-dot form compares against the merge base, which is exactly what the pull request will show.
git commit -am "Add boundary test for 30-minute idle timeout" git push
New commits on the same branch update the pull request. Never open a second pull request for the same change.
gh pr checks --watch✓ test 1m12s ✓ lint 22s
Blocks until the checks finish and exits non-zero if any fail, so it works as a gate in a script.
gh pr edit 231 --add-reviewer ada
CODEOWNERS can do this automatically for the paths a change touches.
gh pr merge 231 --squash --delete-branch
✓ Squashed and merged pull request #231 ✓ Deleted branch feature/login
Squash keeps main readable; deleting the branch in the same command keeps the branch list honest.
Workflow diagrams
The pull request is the gate: nothing reaches main without passing checks and a reviewer.
- Pushing a branch lets you open a pull request against main.
- Automated checks run against the proposed merge result, not just your branch tip.
- Reviewers read the diff and either approve, request changes, or comment.
- Requested changes are handled by pushing more commits to the same branch.
- Once checks are green and the approval requirement is met, the merge button activates.
| Method | What lands on main | Best for | Watch out for |
|---|---|---|---|
| Merge commit | Every branch commit plus a merge commit | Long-lived branches, large features you want to keep step by step | Noisy history with many small "fix typo" commits |
| Squash and merge | One new commit containing the whole change | Feature branches — the default on most teams | The branch’s individual commit messages are not kept separately on main |
| Rebase and merge | Every branch commit, replayed with no merge commit | Linear-history policies, small focused branches | Requires a clean rebase; conflicts must be resolved locally first |
| Closing the PR unmerged | Nothing | Abandoned experiments | The branch and its commits should be deleted too |
All three land the change; they differ in what main looks like afterwards.
- Squash for features: one reviewable commit per idea on main.
- Merge commit when the individual commits matter to the story.
- Rebase when the project requires linear history and the branch is small.
Reviewing is a sequence, not a scroll. Read the intent first so the diff makes sense.
- Start with the description so you know what the author intended.
- Read the diff file by file, questioning edge cases and error paths.
- Check that tests exist for the new behaviour and that CI is green.
- When something must change, request changes and say exactly what and why.
- Otherwise approve, leaving non-blocking suggestions as comments prefixed "nit:".
Worked example
The whole loop from the author’s side, including the reply to a review.
git switch -c fix/session-timeout # ... edit auth/session.py ... git commit -m "Extend session idle timeout to 30 minutes" git push -u origin fix/session-timeout # GitHub prints: Create a pull request for 'fix/session-timeout' on GitHub # https://github.com/ada/app/pull/231 # reviewer requests changes: "add a test for the timeout boundary" git add tests/test_session.py git commit -m "Add boundary test for 30-minute idle timeout" git push # The pull request updates automatically; checks re-run. # after approval, GitHub merges with "Squash and merge" git switch main git pull git branch -d fix/session-timeout git log --oneline -1 # 9d2f4c1 Extend session idle timeout to 30 minutes (#231)
One squashed commit on main, the discussion preserved on the pull request, the branch gone.
Where you'll use it
Common mistakes
- Opening a pull request with no description, forcing reviewers to reverse-engineer the intent from the diff.
- Letting a branch drift for days, so the diff contains unrelated changes by the time it is reviewed.
- Leaving conflicts unresolved and never rebasing, until the review is meaningless.
- Reviewing by rubber-stamping because the diff is 2,000 lines — split it instead.
- Pushing directly to main "just this once" for a small fix, bypassing review entirely.
- Force-pushing to a branch that reviewers are actively reading, which invalidates their line comments.
Best practices
- Open the pull request early, as a draft if needed — visibility beats perfection.
- Keep the diff small; land mechanical changes separately from behavioural ones.
- Write the description so a reviewer needs no context from chat.
- Link the issue with "Closes #123" so the tracker closes itself on merge.
- Prefix non-blocking suggestions with "nit:" so blockers stand out.
- Choose a merge method and keep it consistent, normally squash and merge for feature branches.
- Delete the branch after merging; the pull request keeps the history.
Hands-on exercise
Take one change through a full review cycle
Open a real pull request and behave like both author and reviewer.
- Create a branch, make a small change, commit it, and push with -u.
- Open a pull request with the four-heading description: what, why, how verified, reviewer notes. Include a "Closes #<number>" line if the repository has an issue you can link.
- Open the Files changed tab and leave a review comment on one line — pointing out something real, such as a missing edge case or an unclear name.
- Reply to your own comment, then resolve the conversation, and note how the thread collapses.
- Make the requested improvement, commit it, and push. Confirm the pull request picked up the commit and any checks re-ran.
- Merge with squash and merge, delete the branch, and read the resulting commit message on main.
💡 Hint: You can review your own pull request — use "Add a comment" in the review panel, or start the review from the Files changed tab. It is the fastest way to see both sides of the flow.
Done when: Your repository shows a merged pull request whose main branch contains a single squashed commit, and the branch is deleted.
Checkpoint quiz
0 of 5 answered · 0 correct
- Multiple choiceQ1
What is the main purpose of a pull request?
- TroubleshootingQ2
A reviewer asked for changes. What is the correct way to respond on the same pull request?
- Command outputQ3
You merge with "Squash and merge" and the branch had four commits. What does main look like?
- True or falseQ4
True or false: a draft pull request notifies and requests reviewers.
- Multiple choiceQ5
Which is a good way to keep a pull request reviewable?
Module summary
- A pull request proposes a merge and carries the review, checks and decisions around it.
- A good description says what, why, how it was verified, and what the reviewer should watch for.
- Requested changes are handled by pushing more commits to the same branch.
- Squash keeps main readable, merge commits keep the branch story, rebase keeps history linear.
- Reviewers should read the description first, then the diff, then the tests — and distinguish blockers from nits.
- Delete the branch after merging; the pull request is the permanent record.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.