Learn GitHub
$ gh ghcollaboration.ghpullrequests

Pull Requests and Code Review

6 learning objectives · 10 key terms · 7 commands · 3 diagrams · 5 quiz questions

$objectives

Pull Requests and Code Review

Collaboration

Module 2 of 5 · lesson 5 in this module

What 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
$concept

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

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.
$steps

How it works, step by step

  1. 1
    Push 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 firstbash
    git push -u origin feature/login
  2. 2
    Write 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.

  3. 3
    Write 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.
  4. 4
    Target 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.

  5. 5
    Respond 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.

    iteratebash
    git add login.js
    git commit -m "Extend idle timeout to 30 minutes"
    git push
  6. 6
    Merge 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

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.

push the branchbash
git push -u origin feature/login
Output
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.

open the pull requestbash
gh pr create --base main --title "Extend session idle timeout" --body "Closes #128"
Output
https://github.com/ada/app/pull/231

The closing keyword links the issue, which then closes automatically when the pull request merges.

read your own diff firstbash
git diff main...HEAD --stat
Output
 auth/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.

respond to requested changesbash
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.

watch the checksbash
gh pr checks --watch
Output
✓ 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.

request a reviewerbash
gh pr edit 231 --add-reviewer ada

CODEOWNERS can do this automatically for the paths a change touches.

mergebash
gh pr merge 231 --squash --delete-branch
Output
✓ 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.

$diagrams

Workflow diagrams

Diagram 1From feature branch to merged main

The pull request is the gate: nothing reaches main without passing checks and a reviewer.

Reading the diagram
  1. Pushing a branch lets you open a pull request against main.
  2. Automated checks run against the proposed merge result, not just your branch tip.
  3. Reviewers read the diff and either approve, request changes, or comment.
  4. Requested changes are handled by pushing more commits to the same branch.
  5. Once checks are green and the approval requirement is met, the merge button activates.
Diagram 2Three merge methods, three shapes of history

All three land the change; they differ in what main looks like afterwards.

Reading the diagram
  1. Squash for features: one reviewable commit per idea on main.
  2. Merge commit when the individual commits matter to the story.
  3. Rebase when the project requires linear history and the branch is small.
Diagram 3What a reviewer should actually do

Reviewing is a sequence, not a scroll. Read the intent first so the diff makes sense.

Reading the diagram
  1. Start with the description so you know what the author intended.
  2. Read the diff file by file, questioning edge cases and error paths.
  3. Check that tests exist for the new behaviour and that CI is green.
  4. When something must change, request changes and say exactly what and why.
  5. Otherwise approve, leaving non-blocking suggestions as comments prefixed "nit:".
$example

Worked example

The whole loop from the author’s side, including the reply to a review.

open, revise, mergebash
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)
Output
One squashed commit on main, the discussion preserved on the pull request, the branch gone.
1A focused branch name (fix/session-timeout) tells reviewers what kind of change this is before they open it.
2The push prints a link that opens a pre-filled pull request — GitHub knows the branch has no upstream counterpart yet.
3The reviewer asks for a test. New work goes on the same branch as a new commit; there is never a second pull request for the same change.
4After approval, "Squash and merge" collapses both commits into one on main, with the pull request number appended to the message.
5Locally, switching to main, pulling, and deleting the now-merged branch keeps the branch list honest.
$use cases

Where you'll use it

▸Getting a second pair of eyes on a change before it reaches users.
▸Keeping an auditable record of why a change was made, who approved it, and what was discussed.
▸Running automated tests against the proposed merge result before it lands.
▸Coordinating a change that touches several teams, with each team’s owner reviewing their part.
▸Onboarding new contributors: their pull requests receive review comments and improve fast.
▸Producing release notes from merged pull request titles.
$mistakes

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

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.
$exercise

Hands-on exercise

Take one change through a full review cycle

Open a real pull request and behave like both author and reviewer.

  1. Create a branch, make a small change, commit it, and push with -u.
  2. 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.
  3. 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.
  4. Reply to your own comment, then resolve the conversation, and note how the thread collapses.
  5. Make the requested improvement, commit it, and push. Confirm the pull request picked up the commit and any checks re-ran.
  6. 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.

$quiz

Checkpoint quiz

0 of 5 answered · 0 correct

  1. Multiple choiceQ1

    What is the main purpose of a pull request?

  2. TroubleshootingQ2

    A reviewer asked for changes. What is the correct way to respond on the same pull request?

  3. Command outputQ3

    You merge with "Squash and merge" and the branch had four commits. What does main look like?

  4. True or falseQ4

    True or false: a draft pull request notifies and requests reviewers.

  5. Multiple choiceQ5

    Which is a good way to keep a pull request reviewable?

$summary

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.

Next up: Pull requests need something to point at. Module 6 adds the other half of project work on GitHub: issues to describe the work, and Projects to keep it moving.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

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.