Find a course

Module 4: Working with GitHubLesson 10 of 1212 min

Pull Requests and Code Review

Open a pull request with a clear description, review teammates' changes constructively, and choose between merge, squash and rebase when merging on GitHub.

Step 1 of 13Learn

A second pair of eyes before main

At a small company, a developer pushes a quick fix straight to main late on a Friday. It changes a date format and breaks invoice generation all weekend. Nobody else saw the change before it went live.

A pull request (PR) puts a checkpoint in that path. Instead of merging your branch into main yourself, you push the branch to GitHub and open a pull request: a proposal that says please merge these commits from fix-date-format into main. The PR page shows every changed line, and teammates can comment on specific lines, ask questions, suggest edits and finally approve. Automated checks, such as the test suite, can run on the PR and report pass or fail before anyone merges.

The name comes from asking the maintainers to pull your changes in. GitLab calls the same thing a merge request.

PRs do more than catch bugs. They spread knowledge, because at least one other person understands each change. They create a written record of why a change was made, linked from the commit history. And they're how almost all open-source contribution works: you never need write access to a project to propose an improvement.

Step 2 of 13Learn

Opening a pull request

The flow on GitHub:

  1. Push your branch: git push -u origin fix-date-format.
  2. GitHub shows a banner on the repository page, Compare & pull request. Click it (or go to the Pull requests tab and click New pull request).
  3. Check the two branches at the top. The base is where the changes will go, usually main. The compare branch is yours.
  4. Write a title and description, then click Create pull request.

If your work isn't ready for review but you want to share it, for early feedback or to run the automated checks, choose Create draft pull request. Reviewers won't be requested until you mark it ready.

The PR isn't frozen once opened. Every new commit you push to the same branch appears in the PR automatically. That's how you respond to review feedback: make the changes locally, commit, push, and the PR updates. There's no need to close it and open another.

On the PR page, the tabs to know are Conversation (description, comments, checks and the merge button), Commits and Files changed, where the line-by-line diff and review comments live.

Step 3 of 13Practice · Diagram

Life of a pull request

A reviewer asks for a change. At which stage do you add more commits?

Tap the shape that answers the question, then press Check.

Life of a pull requestProcess diagram: Push a branch → Open the PR → Checks run → Review and update → Merge → Delete branch.Push a branchOpen the PRChecks runReview and updateMergeDelete branch
Push a branch

git push -u origin fix-date-format

Open the PR

Title, description, reviewers.

Checks run

Automated tests report green or red.

Review and update

Comments, more commits pushed to the same branch.

Merge

Approved and green: merge into main.

Delete branch

Keep the branch list short.

Step 4 of 13Practice · Put in order

Put the stages of a typical pull request in order.

Drag the items, or use the arrow buttons, to put them in order.

  1. Reviewers comment and you push follow-up commits
  2. The PR is approved and merged, and the branch is deleted
  3. Push the branch to GitHub
  4. Open a pull request against main
  5. Create a branch and commit your changes

Step 5 of 13Learn

A PR description reviewers will thank you for

Reviewers arrive cold. A good description tells them what they need in under a minute:

  • What the change does, in a sentence or two.
  • Why it's needed: the bug, the request, the problem.
  • How to test it: steps to reproduce the bug and confirm the fix, or a screenshot for visual changes.
  • Anything risky or unfinished that deserves extra attention.
  • A link to the issue, written as Closes #57, so the issue closes automatically when the PR is merged.

For example: Fix invoice dates showing in US format for EU customers. Invoices used the server's locale instead of the customer's. Now formats dates from the customer's country setting. To test: create an order for a German customer and open the PDF invoice. Closes #57.

Size matters more than anything. A PR that changes 80 lines gets a thoughtful review within hours. One that changes 3,000 lines gets skimmed, approved with "looks good," and merged with bugs. Split big work into a series of small PRs that each make sense on their own. Many teams also use a PR template, a .github/pull_request_template.md file that pre-fills the description with headings like these.

Step 6 of 13Practice · Select all that apply

Which of these belong in a helpful pull request description? Select all that apply.

Select all that apply.

Step 7 of 13Learn

Reviewing code well

When you're asked to review, open Files changed. Hover over a line and click the + to leave a comment on it. You can select several lines, and you can use Insert a suggestion to propose an exact replacement that the author can apply with one click.

Comments are collected into a review that you submit with one of three verdicts:

  • Comment: general feedback without approving or blocking.
  • Approve: you're happy for it to merge.
  • Request changes: something must be fixed before merging.

What to look for, in priority order: Does it work and do what the description says? Could it break something else? Is it understandable to the next person? Are there tests? Style nitpicks come last, and are best left to automatic formatters.

Tone matters. You're reviewing code, not the person. Ask questions instead of making accusations (What happens if the list is empty? rather than This crashes). Explain why, not just what. Mark minor points as optional, for example with a "nit:" prefix. Say what's good, too.

As an author, assume good intent, answer every comment, and don't take requested changes personally. Every developer, however senior, gets them.

Step 8 of 13Diagram

Choosing your review verdict

Choosing your review verdictTwo-by-two matrix: Approve, Approve with nits, Comment, Request changes.ApproveApprove with nitsCommentRequest changesProblems foundNoneSomeReady to mergeNot yetYes

Tap a shape with to see more.

Approve

Correct and clear enough to merge.

Approve with nits

Tiny style points; label them optional.

Comment

Questions or ideas while you are not yet sure; not blocking.

Request changes

A real bug or missing test must be fixed before merging.

Step 9 of 13Practice · Match the pairs

Match each review action to when you would use it.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Approve
  2. Request changes
  3. Comment
  4. Insert a suggestion
  5. Mark as draft

Step 10 of 13Learn

The merge button: three options

When a PR is approved and its checks pass, someone clicks the green merge button. GitHub offers up to three methods, which the repository owner can enable or disable:

Create a merge commit. All of the branch's commits are added to main, plus a merge commit joining them. History shows exactly what happened, including every small "fix typo" commit.

Squash and merge. All of the branch's commits are combined into one new commit on main. History stays clean: one commit per PR, with the PR title as its message. The individual work-in-progress commits are gone from main's history, though the PR page keeps them.

Rebase and merge. The branch's commits are replayed individually onto the tip of main without a merge commit, giving a linear history that keeps each commit.

Many teams choose squash because it keeps main readable and makes reverting a whole feature a single git revert. Others prefer merge commits to preserve detail. There's no universal right answer, only a team convention.

After merging, click Delete branch on the PR page, then update your local copy: git switch main, git pull, and delete your local branch with git branch -d fix-date-format.

Step 11 of 13Compare

GitHub merge options

AspectMerge commitSquash and mergeRebase and merge
Commits added to mainAll branch commits plus a merge commitOne new combined commitAll branch commits, replayed
History shapeShows the branch joiningLinear, one commit per PRLinear, every commit kept
Undoing the whole PRRevert the merge commitRevert one commitRevert each commit
Good whenYou want full detailBranch commits are messy or WIPEach commit is clean and meaningful

Step 12 of 13Practice · What would you do?

What would you do?

You're reviewing a teammate's PR and notice the discount calculation applies the coupon twice when a cart has two items of the same product. How do you leave the feedback?

Step 13 of 13Practice · Choose one

A PR has 14 commits with messages like "wip", "fix typo" and "try again". The team wants main to have one clear commit per feature. Which merge option fits best?