GitHub Pull Requests & Code Review

Pull requests are how real teams ship code together. By the end of this lesson you'll push a branch, open a PR, review someone else's changes with approvals and inline comments, and merge it cleanly — the everyday loop of collaborative software.

Learn GitHub Pull Requests & Code Review in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a…

Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

1️⃣ Push the Branch

A PR can only exist for a branch GitHub can see, so the first step is always to push . Use git push -u origin <branch> — the -u sets the upstream so future pushes are just git push , and GitHub immediately prints a link to open the PR.

2️⃣ Open the Pull Request

In GitHub, click Compare & pull request , set the base (the branch you merge into , usually main ) and the compare branch (your changes), then write a clear title and description. Add Closes #42 to auto-close an issue on merge, or open a draft if it's still in progress.

3️⃣ Review the Changes

Reviewing happens on the Files changed tab. Leave inline comments on specific lines, then submit a single review with one verdict: Comment (feedback only), Approve (good to merge), or Request changes (blocks the merge until addressed).

Your turn. Get a feature branch onto GitHub so it's ready for a PR. Fill in the one blank.

4️⃣ Merge and Clean Up

Once it's approved and checks pass, merge with the strategy your team prefers: a merge commit (keeps all commits), squash and merge (one tidy commit), or rebase and merge (linear, no merge commit). Then delete the merged branch and pull main locally.

📋 Quick Reference

No commands given this time — just the plan. Take a change from branch to merged PR, draft and review included.

Practice quiz

What is a pull request (PR)?

  • A request to pull others' code into yours
  • A command that pulls remote changes
  • A proposal to merge one branch into another, with discussion and review
  • A way to delete a branch

Answer: A proposal to merge one branch into another, with discussion and review. A PR proposes merging a branch into a base branch and provides a place to review and discuss the changes.

Before opening a PR, what must you do with your branch?

  • Push it to the remote (e.g. git push -u origin feature)
  • Delete it
  • Rebase main onto it
  • Tag it

Answer: Push it to the remote (e.g. git push -u origin feature). GitHub can only open a PR for a branch it can see, so you push the branch to the remote first.

What does the 'base' branch of a PR mean?

  • The branch your changes come FROM
  • The default branch only
  • A backup branch
  • The branch your changes will merge INTO

Answer: The branch your changes will merge INTO. The base is the target you want to merge into (often main); the compare/head branch holds your changes.

What is a draft pull request used for?

  • A PR that auto-merges
  • Signalling work-in-progress that isn't ready to merge yet
  • A private PR nobody can see
  • A deleted PR

Answer: Signalling work-in-progress that isn't ready to merge yet. Draft PRs share work early for feedback but block merging until you mark them ready for review.

In a review, what does 'Request changes' do?

  • Blocks the merge until the author addresses the feedback
  • Merges immediately
  • Closes the PR
  • Approves the PR

Answer: Blocks the merge until the author addresses the feedback. Request changes is a blocking review state; the PR can't merge (under typical rules) until it's resolved.

What does an 'Approve' review indicate?

  • The reviewer merged it
  • The PR is a draft
  • The reviewer is satisfied and the change can proceed to merge
  • The branch was deleted

Answer: The reviewer is satisfied and the change can proceed to merge. Approve signals the reviewer is happy; with required reviews it satisfies the merge condition.

Which merge option keeps every commit but adds a merge commit?

  • Squash and merge
  • Create a merge commit
  • Rebase and merge
  • Fast-forward only

Answer: Create a merge commit. 'Create a merge commit' preserves all commits and records a merge commit tying the branch in.

What does 'Squash and merge' do?

  • Deletes the PR
  • Rebases main
  • Reverts the change
  • Combines all the branch's commits into one before merging

Answer: Combines all the branch's commits into one before merging. Squash and merge condenses the branch into a single commit on the base, keeping history tidy.

How do you ask GitHub to auto-close an issue when a PR merges?

  • Tag the issue
  • Write 'Closes #123' in the PR description
  • Email the maintainer
  • Add a label

Answer: Write 'Closes #123' in the PR description. Keywords like 'Closes #123' or 'Fixes #123' in the PR link and auto-close the issue on merge.

What is a typical first step a reviewer takes on a PR?

  • Force-push to your branch
  • Delete the base branch
  • Read the diff under the 'Files changed' tab and leave line comments
  • Close the repo

Answer: Read the diff under the 'Files changed' tab and leave line comments. Reviewers read the diff in 'Files changed' and leave inline comments on specific lines.