Skip
Arish's avatar

40. GitHub Pull Requests


GitHub Pull Requests

Pull Requests (PRs) are how you propose changes and get them reviewed before merging into the main codebase.

What is a Pull Request?

A PR lets you:

  1. Show your changes to others
  2. Get feedback through reviews
  3. Discuss implementation
  4. Run automated tests
  5. Merge when approved

Creating a Pull Request

Step 1: Push Your Branch

bash
1git checkout -b feature/new-feature
2# Make changes
3git add .
4git commit -m "Add new feature"
5git push -u origin feature/new-feature

Step 2: Open PR on GitHub

  1. Go to your repository
  2. Click Pull requests tab
  3. Click New pull request
  4. Select branches:
    • Base: main (merge into)
    • Compare: feature/new-feature (your changes)
  5. Click Create pull request

Step 3: Fill PR Details

  • Title: Brief description
  • Description:
    • What changes were made
    • Why they were needed
    • How to test
    • Related issues

PR Description Example

markdown
1## Description
2Add user authentication with email/password login.
3
4## Changes
5- Add login form component
6- Implement authentication logic
7- Add session management
8- Update navigation for logged-in state
9
10## How to Test
111. Go to /login
122. Enter credentials
133. Verify redirect to dashboard
14
15## Screenshots
16[Before/After images]
17
18## Related Issues
19Closes #42
20Relates to #38
21
22## Checklist
23- [x] Tests pass
24- [x] Code reviewed locally
25- [x] Documentation updated

PR Review Process

Requesting Reviews

  1. Click Reviewers in sidebar
  2. Select team members
  3. They'll be notified

Reviewing a PR

As a reviewer:

  1. Go to Files changed tab
  2. Review the diff
  3. Add comments by clicking + on lines
  4. Submit review:
    • Comment - General feedback
    • Approve - Ready to merge
    • Request changes - Needs work

Review Comments

# Inline comment This function could be simplified using map(). # Suggestion ```suggestion const result = items.map(item => item.value); The author can apply suggestions directly! ## PR Status Checks ### Automated Checks - CI/CD tests (GitHub Actions) - Code quality (linters) - Security scans - Coverage reports ### Required Checks Configure in Settings → Branches: - Require status checks to pass - Require reviews before merging ## Updating a PR ### Add More Commits ```bash # On your feature branch git add . git commit -m "Address review feedback" git push # PR automatically updates

Respond to Reviews

  • Reply to comments
  • Mark conversations as resolved
  • Request re-review after changes

Merging a Pull Request

Merge Options

  1. Create merge commit

    • Preserves all commits
    • Adds merge commit
  2. Squash and merge

    • Combines all commits into one
    • Cleaner history
  3. Rebase and merge

    • Linear history
    • Replays commits on base

After Merging

  1. Delete the feature branch
  2. Pull latest main locally:
    bash
    1git checkout main
    2git pull origin main
    3git branch -d feature/new-feature

PR Best Practices

1. Keep PRs Small

# Good: Focused PR Add user login form (200 lines) # Bad: Too large Add entire auth system (2000 lines)

2. One PR = One Purpose

Don't mix unrelated changes.

3. Write Good Descriptions

Explain what, why, and how.

4. Include Tests

bash
1# Run tests before pushing
2npm test

5. Respond Promptly

  • Address feedback quickly
  • Keep the PR moving

6. Use Draft PRs

For work in progress:

  1. Create PR
  2. Convert to draft
  3. Mark ready when done

PR Templates

Create .github/pull_request_template.md:

markdown
1## Description
2Brief description of changes.
3
4## Type of Change
5- [ ] Bug fix
6- [ ] New feature
7- [ ] Breaking change
8- [ ] Documentation update
9
10## Testing
11How to test the changes.
12
13## Checklist
14- [ ] Code follows style guidelines
15- [ ] Tests pass
16- [ ] Documentation updated

Summary

Pull Requests enable:

  • ✅ Code review before merging
  • ✅ Discussion and collaboration
  • ✅ Automated testing
  • ✅ Clean merge history
  • ✅ Documentation of changes

Practice creating PRs in Project Task 4!