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:
- Show your changes to others
- Get feedback through reviews
- Discuss implementation
- Run automated tests
- 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-featureStep 2: Open PR on GitHub
- Go to your repository
- Click Pull requests tab
- Click New pull request
- Select branches:
- Base:
main(merge into) - Compare:
feature/new-feature(your changes)
- Base:
- 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 updatedPR Review Process
Requesting Reviews
- Click Reviewers in sidebar
- Select team members
- They'll be notified
Reviewing a PR
As a reviewer:
- Go to Files changed tab
- Review the diff
- Add comments by clicking
+on lines - 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
-
Create merge commit
- Preserves all commits
- Adds merge commit
-
Squash and merge
- Combines all commits into one
- Cleaner history
-
Rebase and merge
- Linear history
- Replays commits on base
After Merging
- Delete the feature branch
- 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 test5. Respond Promptly
- Address feedback quickly
- Keep the PR moving
6. Use Draft PRs
For work in progress:
- Create PR
- Convert to draft
- 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 updatedSummary
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!
