Pull Requests and Code Review Workflow โ
Introduction โ
Pull Requests (PRs) formalize integration: they bundle changes, surface diffs, trigger automation, and enable peer feedback. This tutorial presents an end-to-end, platform-agnostic workflow (GitHub/GitLab/Bitbucket apply similar concepts).
Why Use Pull Requests? โ
- Quality gate (tests, lint, security scans)
- Knowledge sharing
- Change accountability & audit trail
- Encourages smaller, reviewable units
Standard Branch Naming โ
| Type | Pattern | Example |
|---|---|---|
| Feature | feature/<scope> | feature/payment-intents |
| Bugfix | fix/<issue-id> | fix/342-null-pointer |
| Refactor | refactor/<area> | refactor/auth-middleware |
| Docs | docs/<topic> | docs/api-pagination |
PR Lifecycle Overview โ
Plan โ Branch โ Commit โ Sync โ Open PR โ Review โ Update โ Approve โ Merge โ Clean upCreating a PR (Example: GitHub CLI) โ
bash
git checkout -b feature/user-deactivation
# ... commits ...
git push -u origin feature/user-deactivation
gh pr create --fill --base main --head feature/user-deactivationConstructing High-Quality PRs โ
Checklist:
- Clear title (imperative form)
- Concise description: problem โ solution โ notes
- Screenshots / GIFs for UI changes
- Linked issue IDs (
Fixes #123) - Test coverage notes
- Rollback considerations
Example Description Template โ
## Summary
Implements soft-delete user deactivation flow.
## Changes
- Add `status` column
- Introduce service layer method `deactivateUser()`
- Migrate existing active users
## Testing
- Unit tests added
- Manual API test (POST /users/:id/deactivate)
## Rollback
Revert migration 202510071230_add_status_column.sqlReview Best Practices โ
Reviewer responsibilities:
- Understand intent before nitpicking syntax
- Assess correctness, security, performance, readability
- Suggest, donโt demand (unless policy)
- Approve only when production-safe
Author responsibilities:
- Keep PRs small (< ~400 added lines ideally)
- Respond to every comment (resolve / explain)
- Avoid force-pushing after review unless squashing at end
- Maintain green CI
Handling Feedback โ
bash
# Make changes
git commit -m "Refactor: extract validation helper"
git pushPlatform auto-updates PR diff.
Draft vs Ready โ
Use draft mode while still stabilizing logic. Convert to ready once tests and self-review complete.
Automations to Consider โ
| Automation | Purpose |
|---|---|
| CI pipeline | Run tests/lint/build |
| Static analysis | Security / quality gates |
| Conventional commit check | Enforce message style |
| Size labelling | Flag oversized PRs |
| Auto assign / reviewers | Shorten latency |
Merge Strategies in PR โ
| Strategy | Description | Use |
|---|---|---|
| Squash | Combine commits into one | Small, noisy commit history |
| Rebase & merge | Linearizes branch | Teams preferring linear history |
| Merge commit | Preserve branch context | Feature groups / release trains |
Rebase Before Merge (If Policy) โ
bash
git fetch origin
git rebase origin/main
git push --force-with-leaseAvoiding Common Anti-Patterns โ
| Anti-Pattern | Problem |
|---|---|
| Massive PR ("God diff") | Hard to review โ bugs slip |
| Mixing refactor + feature | Obscures intent |
| Force-push after review comments | Invalidates prior review |
| No description | Reviewers guess intent |
| Ignoring failing CI | Wastes reviewer time |
Post-Merge Cleanup โ
bash
git checkout main
git pull origin main
git branch -d feature/user-deactivation
git push origin --delete feature/user-deactivationMetrics to Track (Team Level) โ
- Review turnaround time
- PR size distribution
- Re-opened / reverted merges
- Ratio of squash vs merge commits
Summary โ
Well-structured PRs accelerate safe delivery. Optimize for clarity, small scope, automated validation, and respectful, actionable feedback loops.
Next Steps โ
- Conflict strategies (
git-conflict-resolution-strategies.md) - Team collaboration guide (
git-best-practices-for-team-collaboration.md)
Key Commands
bash
git push -u origin <branch>
git branch -d <branch>
git push origin --delete <branch>