On most teams, code doesn't go straight onto the main branch. It's proposed as a change, discussed, reviewed, checked by automation, and only then merged. GitHub, Bitbucket, Azure Repos, Gitea, and Forgejo call this a pull request; GitLab calls it a merge request; projects that work by email send a patch series. This lesson covers the lifecycle of a proposed change, how to write one that's easy to review, how to review well, the merge methods platforms offer, and how the same ideas work with forks and email.
Before you start
You should be comfortable with branches and remotes from the Basic level, and know the platform landscape from GitHub vs GitLab vs Bitbucket vs Codeberg: Understanding Git Hosting Platforms. Having two accounts, or a teammate, on any platform helps for the exercise.
What a pull request is
A pull request (PR) or merge request (MR) is not a Git feature. It's a platform object that says: "please merge branch X into branch Y," with a discussion attached. Underneath, it's ordinary branches and commits; the platform adds:
- a diff view of the proposed change;
- comments, on the whole change or on specific lines;
- reviews: approve, comment, or request changes;
- status checks from CI (lesson 10 and 11) showing whether tests pass;
- rules such as required approvals before merging;
- a merge button that performs the merge with the method the project allows.
Because it's platform data, the conversation stays on the platform when you move a repository. Lesson 15 covers exporting it.
The lifecycle of a change
- Branch from the current main branch:
git switch -c fix/cart-rounding. - Commit focused changes with clear messages.
- Push the branch:
git push -u origin fix/cart-rounding. - Open the PR or MR. Platforms usually print a link after the push. Open it as a draft if it's not ready, to share early or get CI feedback.
- Automation runs: tests, linters, and builds report status on the change.
- Review: reviewers comment; you answer and push more commits to the same branch, and the PR updates automatically.
- Approve and merge once checks pass and the rules are met.
- Clean up: delete the branch, and pull the updated main branch locally.
Writing a change that's easy to review
The author does most of the work that makes review effective.
Keep it small
Review quality drops sharply as changes grow. A few hundred changed lines can be reviewed carefully; a few thousand get skimmed. Split large work into a sequence of PRs, each one useful and safe on its own: first the refactor that makes room, then the feature, then the cleanup.
Explain the why
The diff shows *what* changed. The description must say *why*, and anything the reviewer needs to verify it:
## Why
Checkout showed "-0.00" when every item in the cart was free (#412).
## What changed
- Round totals in every case, not only when the total is positive.
- Add tests for an all-free cart and a single free item.
## How to verify
1. Add only the free sample to the cart.
2. Open checkout: the total shows 0.00.
## Notes for reviewers
The rounding helper moved to `money.ts`; the rest is unchanged.Many platforms support a template file (for example, .github/pull_request_template.md on GitHub, or description templates in .gitlab/merge_request_templates/ on GitLab) so every PR starts with these headings.
Review your own change first
Before asking anyone, read your own diff on the platform as a reviewer would. You'll catch debugging leftovers, unrelated formatting changes, and missing tests, and save a review round.
Reviewing well
Good review finds problems and spreads knowledge, without becoming a gatekeeping ritual. Look at, roughly in order of importance:
- Design: does this change belong here, and does it fit the system? Is there a simpler approach?
- Correctness: does it do what it claims, including edge cases and errors? Are there tests, and do they test the right thing (see How to Write Effective Test Cases)?
- Security and data: input handling, permissions, secrets, personal data.
- Readability: will the next person understand it? Are names clear?
- Style: only what automated tools don't already enforce. Let formatters and linters handle formatting.
How you comment matters as much as what you find:
- Be specific and kind. Comment on the code, not the person.
- Say how important each comment is. Prefixes such as "nit:" (minor), "question:", or "blocking:" prevent misunderstandings about what must change.
- Explain why, and suggest an alternative when you can. Many platforms let you propose an exact replacement that the author can apply with one click.
- Approve when the change makes the code better overall, even if it's not exactly how you'd have written it.
- Respond quickly. Slow reviews push authors toward bigger, riskier PRs.
Reviewing locally
Some changes are easier to judge by running them. Fetch the branch and try it:
git fetch origin fix/cart-rounding
git switch fix/cart-rounding
npm testFor PRs from forks, platforms expose read-only references you can fetch directly. GitHub publishes them as refs/pull/<number>/head and GitLab as refs/merge-requests/<number>/head:
git fetch origin refs/pull/412/head:review/412
git switch review/412Merge methods
Platforms usually offer three ways to merge, and projects often restrict them to one:
- Merge commit: keeps every commit from the branch, plus a merge commit. Full history, but a busier graph.
- Squash merge: combines all the branch's commits into one commit on the main branch. Clean main history, one commit per change; the individual commits are lost from the main branch (the platform usually keeps them in the PR).
- Rebase merge (or fast-forward): replays the branch's commits onto main, with no merge commit. Linear history that keeps each commit, which works best when every commit is clean and passes tests.
Squash merging is popular because it forgives messy work-in-progress commits. If you use it, make the final squashed message good: it's the one that stays in history.
Rules that protect the main branch
Platforms let you protect important branches. Common rules:
- no direct pushes; changes arrive only through reviewed PRs;
- at least one approval, and new pushes dismiss earlier approvals;
- required status checks (CI must pass) before merging;
- branches must be up to date with main before merging, or a merge queue tests the combined result;
- no force pushes or deletion.
A code owners file (CODEOWNERS, supported by GitHub and GitLab, among others) automatically requests reviews from the people responsible for particular paths:
# Payments code needs a payments reviewer
/src/payments/ @your-org/payments-team
# Workflows and deployment need an ops reviewer
/.github/ @your-org/opsContributing from forks
On open-source projects, contributors usually can't push branches to the original repository. Instead they fork it (make their own copy on the platform), push a branch to their fork, and open a PR from the fork to the original. Keep your fork's main branch in sync by fetching from upstream, as in lesson 5, and start each new branch from the updated main.
Maintainers can often push small fixes to a contributor's branch if the contributor allows it, which saves a review round for trivial changes.
Review by email
Projects such as the Linux kernel and Git itself review changes as emailed patches, and platforms like SourceHut are built around this. Git has the tools built in:
git format-patch -3 --cover-letter -o outgoing/ # the last three commits as patch files
git send-email --to=list@project.test outgoing/*.patch
# A maintainer applies them with:
git am outgoing/*.patchReviewers reply inline, and a revised version of the series is sent as "v2". The ideas are the same as with pull requests: small, well-explained changes, line-level feedback, and iteration.
Common mistakes and troubleshooting
- One giant PR. Split it; reviewers can't hold thousands of lines in their heads.
- An empty description. Say why, what, and how to verify.
- Mixing a refactor with a behavior change. Reviewers can't tell which lines matter. Separate them.
- Arguing style in review. Automate it with a formatter and linter.
- Approving without reading or running anything. Review is a responsibility; if you didn't check, say what you didn't check.
- "This branch has conflicts." Update your branch from main (merge or rebase), resolve locally, and push.
- CI passes locally but fails on the PR. The PR may be tested against the latest main; fetch and rebuild with it.
Practical exercise: a full review cycle
With a teammate, or two accounts:
- Protect
mainon a test repository: require one approval and a passing check, and disallow direct pushes. - As author, create a branch with a small change and a deliberate small mistake. Push and open a PR with a why, what, and how-to-verify description.
- As reviewer, fetch the branch locally, run it, and leave one blocking comment and one "nit:" comment, including a suggested change.
- As author, apply the suggestion, fix the mistake, push, and reply.
- Approve, merge with squash, and check the final commit message on main.
- Optional: send the same change as a patch with
git format-patchand apply it in a fresh clone withgit am.
Key takeaways
- Pull requests and merge requests are platform features built on ordinary branches and commits.
- Small, focused changes with a clear description get better reviews, faster.
- Review design and correctness first; automate style.
- Merge commits, squash merges, and rebase merges trade history detail against readability.
- Protect main with required reviews and checks; use code owners for important paths.
- Forks and email patches follow the same principles.
References
- Pro Git: Distributed Workflows (opens in a new tab)
- Pro Git: Contributing to a Project (opens in a new tab)
- Google Engineering Practices: Code Review (opens in a new tab)
- GitHub Docs: About pull requests (opens in a new tab)
- GitLab Docs: Merge requests (opens in a new tab)
- Git documentation: git format-patch (opens in a new tab)
- Forgejo: Pull requests and Git flow (opens in a new tab)
What's next
How long should branches live, and how do they flow into releases? Git Branching Strategies: Trunk-Based Development, Git Flow, and Feature Branches compares the main approaches.

