G
GuideDevOps
Lesson 13 of 18

Pull Requests & Code Reviews

Part of the Git & Version Control tutorial series.

What is a Pull Request?

A pull request (PR) is a request to merge your branch into main. It enables code review and team discussion before integration.

The Flow

Your Branch → Create PR → Review → Approve → Merge

Creating a Pull Request

Push Your Branch

git checkout -b feature/search
# ... make commits ...
git push -u origin feature/search

Create PR on GitHub/GitLab

GitHub:

  1. Go to repository
  2. Click "Pull Requests"
  3. Click "New Pull Request"
  4. Select: base = main, compare = feature/search
  5. Add title and description

GitLab:

  1. Code → Merge Requests
  2. New Merge Request
  3. Select source/target branches
  4. Describe the change

PR Title and Description

Good PR Title:

Add search box to homepage
Implement autocomplete for search feature
Fix race condition in payment processing

PR Description Template:

## What does this PR do?
Adds search functionality to homepage with autocomplete suggestions.
 
## Why?
Users want quick access to find content.
 
## How to test?
1. Click search box
2. Type "hello"
3. See autocomplete suggestions
4. Click one to search
 
## Related Issues
Closes #432

Reviewing Pull Requests

Code Review Checklist

  • ✅ Code follows style guide
  • ✅ No security vulnerabilities
  • ✅ Functions are well-named
  • ✅ Tests added for new functionality
  • ✅ Documentation updated if needed
  • ✅ No hardcoded values or debug code
  • ✅ Performance acceptable

Commenting on Code

For specific code sections:

# In diff view, click line to comment
 
# Example comment:
"This function is doing too much. Maybe split into 
smaller functions for better readability?"

Approving vs. Requesting Changes

  • Approve: Code looks good, ready to merge
  • Request Changes: Needs fixes before merge
  • Comment: General feedback, not blocking

Addressing Feedback

Respond to Comments

# Make changes based on feedback
git add fixed-file.ts
git commit -m "Clean up function as requested in review"
 
# Push to same branch
git push
# PR automatically updates with new commit

Resolving Comments

After making requested changes:

  • Comment: "Done" or cross out comment
  • Some platforms allow "Resolve" button

PR Status Checks

Automated Checks

Common CI/CD checks that run on PR:

  • ✅ Build succeeds
  • ✅ Tests pass
  • ✅ Linter passes
  • ✅ Code coverage above threshold
  • ✅ No security vulnerabilities
# In PR status:
All checks passing Ready to merge
Build failing Fix and push Re-run checks

Failing Checks

If check fails:

# Fix locally
npm run build  # or npm test, npm run lint
git add .
git commit -m "Fix build error"
git push
# Checks automatically re-run on GitHub

Merging Pull Requests

Merge Methods

MethodResultUse
Create merge commitMerge commit createdOfficial record
Squash and mergeSingle commitClean history
Rebase and mergeLinear historyFast-forward

Merge Process

Interactive:

  • Click "Merge pull request"
  • Choose merge method
  • Confirm

Command line:

# Review changes
git diff main feature/auth
 
# Merge locally
git checkout main
git pull
git merge --no-ff feature/auth
 
# Push
git push

After Merge

Delete the feature branch:

# Local
git branch -d feature/auth
 
# Remote (or delete via GitHub UI)
git push origin --delete feature/auth

Advanced PR Workflows

Draft Pull Requests

For work-in-progress:

  • Click "Mark as draft" before ready
  • CI/CD usually skipped
  • Signals "not ready for review"
git push origin feature/wip
# Create PR but mark as DRAFT

Requesting Reviewers

# On GitHub
Assignees Select team members
Reviewers Select who should review
 
# GitHub notifies them

PR Conversation

## Reviewer
"This logic seems inefficient - did you consider caching?"
 
## Author
"Good catch! Updated to cache results. 
Benchmarks show 40% improvement. Check commit abc1234."
 
## Reviewer
"✅ Looks great now"

Common PR Mistakes

❌ Too Large

PR with 500+ lines changed.

Fix: Break into smaller, focused PRs.

❌ No Description

PR with title "Update" and empty description.

Fix: Describe what, why, and how to test.

❌ Unrelated Changes

PR claims to fix bug but includes refactoring.

Fix: One logical change per PR.

❌ Ignoring Feedback

Pushing same code after review comments.

Fix: Address feedback or discuss why not changing.

Workflow: Complete PR Cycle

# 1. Create feature branch
git checkout -b feature/notifications
git add notification.ts
git commit -m "Add email notifications"
 
# 2. Push and create PR
git push -u origin feature/notifications
# Go to GitHub → Create PR
 
# 3. Wait for review
# Reviewer checks code
 
# 4. Address feedback
git add notification.ts
git commit -m "Add error handling as requested"
git push
 
# 5. Get approval + tests pass
# Click "Merge pull request"
 
# 6. Delete branch
git push origin --delete feature/notifications

Tips

✓ One logical change per PR
✓ Write clear, descriptive titles
✓ Add context in description
✓ Keep PRs small (100-400 lines)
✓ Respond to feedback respectfully
✓ Don't force-push after PR created
✓ Clean up branches after merge