# Pull Requests

> A dedicated workspace for teams to review, discuss, and refine code before merging.

Subject: Version Control | Lesson 25 of 29 | 6 min read
Interactive lesson: https://codewithanimation.in/git/pull-requests
Previous: [Rebase vs Merge](https://codewithanimation.in/git/rebase-vs-merge.md) | Next: [Forking & Cloning](https://codewithanimation.in/git/forking-and-cloning.md)

## The Code Gateway

A **Pull Request** (or Merge Request on GitLab) is a formal proposal to merge code changes from a working branch into another branch (typically `main`).

It provides a dedicated workspace for a team to review diffs, discuss implementations, and refine the proposed code before it is officially integrated into the project.

## Why it matters

**Code Review:** It allows peers to spot bugs, enforce coding standards, and share knowledge before code is shipped.

**CI/CD Checks:** PRs act as triggers for automated tests to ensure new changes don't break existing functionality.

**Protecting Main:** It serves as a strict gatekeeper for the `main` branch, ensuring only stable, reviewed, and approved code gets deployed.

## How it works

**1. Open:** After pushing a feature branch, a developer opens a PR targeting the base branch.

**2. Review:** Reviewers examine the exact additions and deletions (diffs), leave comments, request changes, or approve the PR.

**3. Merge:** Once approved and all automated CI checks pass, the PR is merged into the base branch, and the feature branch is typically deleted.

## Common mistake: The 2000-Line Monster

The #1 common mistake is creating massive, monolithic PRs.

Large PRs are notoriously difficult and exhausting to review. This leads to delayed feedback, surface-level 'Looks Good To Me' (LGTM) approvals where reviewers just skim the code, and a significantly higher risk of introducing hidden bugs into production.

## Tip: The PR is a Sales Pitch

Mental Model: *Treat your PR description as a sales pitch to your reviewer.*

Don't leave it blank. Provide context on *why* this change is needed and *how* you implemented it. Include before-and-after screenshots for UI changes, and leave comments on your own PR to highlight complex logic where you specifically want feedback.

## Try it: Follow a pull request

Open a simulated request, review the change and merge it into the target branch.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/git/pull-requests

## Check yourself

### Question 1

What is the primary purpose of a Pull Request?

- A. To execute code directly on the production server.
- B. To download the latest changes from the remote repository to your local machine.
- C. To propose, review, and discuss code changes before merging them into a branch.
- D. To automatically resolve all merge conflicts in the project.

Correct answer: C

PRs provide a collaborative environment to review and refine code before integration.

- Why not A: Deployments happen after merging, not via the PR itself.
- Why not B: That is what `git pull` does, not a Pull Request.
- Why not D: Conflicts still have to be resolved manually by developers.

### Question 2

Why is it highly recommended to keep Pull Requests small?

- A. Because Git has a strict 500-line limit per Pull Request.
- B. Small PRs are easier and faster to review, reducing the chance of bugs slipping through.
- C. Small PRs bypass the need for automated CI/CD checks.
- D. So that developers can artificially increase their total count of merged PRs.

Correct answer: B

Smaller changes are easier to digest, leading to more thorough, effective, and timely reviews.

- Why not A: Git has no strict line limit for PRs.
- Why not C: Small PRs should still run through CI/CD.
- Why not D: PR quantity is not a meaningful metric compared to code quality.

### Question 3

What happens when you finally merge an approved Pull Request?

- A. The approved changes from the head branch are incorporated into the base branch.
- B. The entire repository is duplicated to your local machine.
- C. The base branch is overwritten and its entire history is deleted.
- D. A new fork of the repository is automatically created.

Correct answer: A

Merging integrates the proposed, reviewed code from your feature branch into the target branch (like `main`).

- Why not B: This describes a clone.
- Why not C: Merging preserves history, it does not delete it.
- Why not D: Forking is a separate process.

## Remember this

- A PR is a proposal to merge code.
- It is the primary space for code review and CI checks.
- Keep PRs small to ensure high-quality reviews.
- Write excellent descriptions to help your reviewers.
