Mainframe Path Start learning free
Beginner7 min readLesson 4 of 4

GitHub pull requests and code review

A pull request asks for a branch to be merged into main and gives the team a place to review it first. Reviewers comment on the exact lines, automated checks run, and once the required approvals and checks pass, the branch is merged and usually deleted.

From branch to main, with review

  1. Push your branch to GitHub.
  2. Open a pull request (PR) from your branch into main. Give it a clear title and say what changed, why, and how you tested it.
  3. Reviewers read the diff and comment on specific lines, ask questions, request changes or approve.
  4. Automated checks run at the same time, such as the build and the tests, often from Jenkins or GitHub Actions. Each shows a green tick or a red cross on the PR.
  5. You push fixes to the same branch. The PR updates itself and the checks run again.
  6. When the rules are met, someone merges it, and the branch is usually deleted.

Rules that protect main

Repository administrators set branch protection rules on main (GitHub's newer *rulesets* do the same job). Typical rules: no direct pushes, at least one approval, all required checks green, and the branch up to date with main. These rules make 'someone reviewed it and the tests passed' a guarantee rather than a hope.

Three ways to merge a PR

OptionWhat ends up on main
Create a merge commitAll of the branch's commits, plus a merge commit joining them
Squash and mergeOne single commit containing the whole change. Keeps main's history short
Rebase and mergeThe branch's commits replayed on top of main, with no merge commit

Teams pick one style and stick to it. Many choose squash, so that each PR becomes one tidy commit on main.

Forks

On a team repository you normally push branches to the same repository. When you have no write access, as with open-source projects, you fork it: GitHub makes your own copy, you push your branch there, and you open the pull request from your fork back to the original.

Reviewing well

TRY IT YOURSELF

What is the name of the GitHub feature that asks for a branch to be reviewed and merged into main? (two words)

Show a hint

You ask the project to 'pull' your branch.

Show the solution

A pull request (PR).

Common mistakes

Opening one huge pull request

Large PRs get skimmed, not reviewed. Split the work into small PRs that each make sense on their own.

Merging with red checks

A failing check is the pipeline telling you something is broken. Fix it, or find out why, before you merge.

Leaving the description empty

Reviewers need to know what changed, why, and how you tested it. Two or three sentences save a lot of questions.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
← Branches, merging and conflictsBack to Git and GitHub