Pull Requests
A pull request (PR) asks: “please merge my branch into main”. It is where code gets reviewed before it goes live.
On this page · 5 min · Intermediate
On this page
- Learning objectives
- Explanation
- Step-by-step screens
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Intermediate
- Updated
- Nov 25, 2026
Learning objectives#
- Open a pull request from a branch
- Read the Files changed tab
- Review, comment and approve
- Merge and delete the branch
Explanation#
After pushing a branch, GitHub shows a yellow Compare & pull request banner. Check the direction (base: main ← compare: your branch), write a title and description, add reviewers and create the PR.
The Files changed tab shows the difference: green lines added, red lines removed. Reviewers click a line to comment, then use Review changes to Comment, Approve or Request changes.
When the review is approved and checks pass, click Merge pull request → Confirm merge. GitHub then offers Delete branch. Locally, switch to main and pull to get the merged code.
Even when working alone, PRs are useful: they show exactly what you changed, run your automated checks, and give a clean history of features.
Step-by-step screens#
Drawings of github.com, the Git installer, VS Code and a terminal. GitHub changes its layout from time to time; the button names stay the same. The red numbers match the numbered actions under each picture; names on your computer will differ.
Loading pictures…
Code example: The same flow with the GitHub CLI#
gh pr create --base main --title "Add contact form" --body "Adds /contact with validation"
gh pr view --web # open it in the browser
gh pr merge --merge --delete-branch
git switch main
git pull
https://github.com/asha/hello-github/pull/3 ✓ Merged pull request #3 (Add contact form) ✓ Deleted branch feature/contact-form
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- gh pr create opens the PR from the current branch.
- Reviewers look at it in the browser.
- gh pr merge merges and deletes the branch.
- Switch to main and pull to get the result.
Real-world use case#
In a group project, nobody pushes to main directly; every change goes through a PR so at least one teammate reads it first.
Common mistakes#
Nobody reviews 2,000 lines properly. Keep PRs small and focused.
Your local main is now behind. git switch main && git pull.
Best practices#
- Small PRs with a clear description
- Explain how to test
- Reply to every review comment
- Delete merged branches
Remember this#
Compare & pull request.
Files changed = the diff.
Approve → Merge → Delete branch.
Practice exercise#
Your task: After a PR was merged on GitHub, update your local main branch.
Show solution
git switch main
git pull
Mini quiz#
In a PR to merge feature/x into main, which is the base branch?
Want more? Practise all Git & GitHub MCQs · Git & GitHub interview questions
My notes#
Saved in this browser.