10 minlesson

Pull Requests and Code Review

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:

bash
1# Auto-fill title and body from commits
2$ gh pr create --fill
3Creating pull request for feature/login-form into main in user/repo
4
5https://github.com/user/repo/pull/42

With Custom Title and Body

bash
1$ gh pr create --title "Add login form" --body "This PR adds a login form with validation."

Interactive Mode

bash
1$ gh pr create
2? Where should we push the 'feature/login-form' branch? user/repo
3? Title Add login form
4? Body <Received>
5? What's next? Submit

Via GitHub Web

  1. Push your branch: git push -u origin feature/login-form
  2. Go to your repository on GitHub
  3. Click "Compare & pull request" banner
  4. Fill in title and description
  5. Click "Create pull request"

PR Best Practices

Write Good Descriptions

Template:

markdown
1## Summary
2Brief description of what this PR does.
3
4## Changes
5- Added login form component
6- Implemented form validation
7- Added unit tests
8
9## Testing
10How to test these changes:
111. Navigate to /login
122. Submit form with invalid email
133. Verify error message appears
14
15## Screenshots
16[If UI changes]

Keep PRs Small

PR SizeLines ChangedReview Time
Small< 200Minutes
Medium200-400Hours
Large400+Days

Large PRs are harder to review thoroughly. Split big features into smaller, incremental PRs.

Link to Issues

Reference related issues in your PR:

markdown
1Fixes #42
2Closes #123
3Related 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-------M
2 \ /
3feature: C---D
bash
1$ gh pr merge --merge

Squash and Merge

Combines all commits into one clean commit:

main: A---B---E (squashed C+D)
bash
1$ 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)
bash
1$ 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:

bash
1$ gh pr create --draft

Convert to ready when done:

bash
1$ gh pr ready

Viewing and Managing PRs

List Open PRs

bash
1$ gh pr list
2ID TITLE BRANCH STATUS
342 Add login form feature/login-form Open
437 Update dependencies chore/deps Open

View PR Details

bash
1$ gh pr view 42
2Add login form #42
3Open • user wants to merge 3 commits into main from feature/login-form
4...

Check PR Status

bash
1$ gh pr status
2Relevant pull requests in user/repo
3
4Current branch
5 #42 Add login form [feature/login-form]

After Merge

Delete Remote Branch

GitHub can auto-delete branches after merge. Or manually:

bash
1$ gh pr merge --delete-branch

Update Local Repository

bash
1$ git switch main
2$ git pull --ff-only
3$ 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.