Pull Requests and Code Review
Pull requests (PRs) are the gateway for getting your code into main. They enable code review, discussion, and automated checks before merging.
What is a Pull Request?
A pull request:
- Proposes merging one branch into another
- Shows all changes in a reviewable format
- Enables discussion through comments
- Can trigger automated tests (CI)
- Creates an audit trail of changes
Creating Pull Requests
Using GitHub CLI
The fastest way to create a PR from the terminal:
bash1# Auto-fill title and body from commits2$ gh pr create --fill3Creating pull request for feature/login-form into main in user/repo45https://github.com/user/repo/pull/42
With Custom Title and Body
bash1$ gh pr create --title "Add login form" --body "This PR adds a login form with validation."
Interactive Mode
bash1$ gh pr create2? Where should we push the 'feature/login-form' branch? user/repo3? Title Add login form4? Body <Received>5? What's next? Submit
Via GitHub Web
- Push your branch:
git push -u origin feature/login-form - Go to your repository on GitHub
- Click "Compare & pull request" banner
- Fill in title and description
- Click "Create pull request"
PR Best Practices
Write Good Descriptions
Template:
markdown1## Summary2Brief description of what this PR does.34## Changes5- Added login form component6- Implemented form validation7- Added unit tests89## Testing10How to test these changes:111. Navigate to /login122. Submit form with invalid email133. Verify error message appears1415## Screenshots16[If UI changes]
Keep PRs Small
| PR Size | Lines Changed | Review Time |
|---|---|---|
| Small | < 200 | Minutes |
| Medium | 200-400 | Hours |
| Large | 400+ | Days |
Large PRs are harder to review thoroughly. Split big features into smaller, incremental PRs.
Link to Issues
Reference related issues in your PR:
markdown1Fixes #422Closes #1233Related to #456
GitHub automatically closes linked issues when the PR merges.
Merge Strategies
Merge Commit
Creates a merge commit preserving all branch history:
1main: A---B-------M2 \ /3feature: C---D
bash1$ gh pr merge --merge
Squash and Merge
Combines all commits into one clean commit:
main: A---B---E (squashed C+D)
bash1$ gh pr merge --squash
Best for: Feature branches with messy commit history.
Rebase and Merge
Replays commits on top of main (linear history):
main: A---B---C'---D' (rebased)
bash1$ gh pr merge --rebase
Best for: Clean commit history without merge commits.
PR Lifecycle
1┌─────────────┐ ┌─────────────┐ ┌─────────────┐2│ Draft │───▶│ Review │───▶│ Merged │3└─────────────┘ └─────────────┘ └─────────────┘4 │ │5 │ ▼6 │ ┌─────────────┐7 └───────────▶│ Changes │8 │ Requested │9 └─────────────┘
Draft PRs
Open a draft when you want early feedback but aren't ready for full review:
bash1$ gh pr create --draft
Convert to ready when done:
bash1$ gh pr ready
Viewing and Managing PRs
List Open PRs
bash1$ gh pr list2ID TITLE BRANCH STATUS342 Add login form feature/login-form Open437 Update dependencies chore/deps Open
View PR Details
bash1$ gh pr view 422Add login form #423Open • user wants to merge 3 commits into main from feature/login-form4...
Check PR Status
bash1$ gh pr status2Relevant pull requests in user/repo34Current branch5 #42 Add login form [feature/login-form]
After Merge
Delete Remote Branch
GitHub can auto-delete branches after merge. Or manually:
bash1$ gh pr merge --delete-branch
Update Local Repository
bash1$ git switch main2$ git pull --ff-only3$ git branch -d feature/login-form
Code Review Tips
As a Reviewer
- Review in small sessions (avoid fatigue)
- Check for logic errors, not just style
- Ask questions rather than making demands
- Approve when comfortable, not when perfect
As an Author
- Respond to all comments
- Don't take feedback personally
- Explain your reasoning
- Push updates as new commits (easier to review)
Key Takeaway
Pull requests are where code gets reviewed and approved. Write clear descriptions, keep PRs small, and choose the right merge strategy. Use gh pr commands to manage PRs efficiently from the terminal.