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.
What You'll Learn
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.
Common Errors (and the fix)
- "No 'Compare & pull request' button": you didn't push the branch, or pushed to the wrong remote. Run git push -u origin <branch> and refresh.
- PR shows far more changes than expected: your branch is behind main . Update it (merge or rebase main in) so the diff only shows your work.
- Can't merge — "Changes requested": a reviewer used Request changes. Address the comments, push the fixes, and ask for a re-review.
- Merge button greyed out: required status checks (CI) haven't passed, or required reviews are missing. Fix the checks and get the approvals.
- Issue didn't auto-close: the closing keyword must be in the PR description/commit and the issue in the same repo — use Closes #N , not just "#N".
Pro Tips
- 💡 Small PRs get reviewed faster: one focused change per PR beats a giant one.
- 💡 Describe the "why": reviewers approve faster when the description explains the reasoning, not just the code.
- 💡 Use draft early: open a draft as soon as CI matters, so checks run while you keep working.
- 💡 Learn gh : gh pr create , gh pr checkout 57 , and gh pr merge keep you in the terminal.
📋 Quick Reference
Action
How
git push -u origin branch
Publish a branch for a PR
gh pr create --fill
Open a PR from the terminal
Closes #42
Auto-close an issue on merge
gh pr review --approve
Approve a PR
gh pr merge --squash
Squash-merge a PR
gh pr ready
Mark a draft ready for review
Frequently Asked Questions
Mini-Challenge: A Full PR Round-Trip
No commands given this time — just the plan. Take a change from branch to merged PR, draft and review included.
🎉 Lesson Complete!
- ✅ Push a branch with -u before opening a PR
- ✅ A PR merges a compare branch into a base branch, with review built in
- ✅ Draft PRs share work-in-progress without allowing a merge
- ✅ Reviews are Approve, Comment, or the blocking Request changes
- ✅ Merge with a merge commit, squash, or rebase — then delete the branch
- ✅ Next lesson: fork a repo and contribute to open-source projects
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.
Continue this course
- Previous: Git Configuration & Aliases
- Next: Forking & Contributing to Open Source