Pull requests

Topic 2 of 4 in GitHub essentials8 min readBeginnerFree course

Overview

A pull request (PR) is a proposal: “please merge my branch into main”. It’s the heart of collaboration on GitHub. Around that one request, GitHub gathers everything a team needs to decide whether the change is ready: the diff, a description, discussion, code review, automated test results and the merge button.

(GitLab calls the same thing a merge request.)

The life of a pull request: branch (git switch -c), commit and push (git push -u), open the PR and describe it, checks and review by CI and teammates, then merge into main. If changes are requested, push more commits and the cycle repeats. Merge options, which the repository decides: create a merge commit (keeps every commit plus a merge commit), squash and merge (one commit per PR on main), or rebase and merge (replays commits, no merge commit).

Opening a pull request

  1. Do your work on a branch and push it:
Terminal
git switch -c feature/about-page
# …commits…
git push -u origin feature/about-page
  1. Open the PR. GitHub shows a “Compare & pull request” banner for recently pushed branches, or use the Pull requests → New pull request page. From the terminal:
Terminal
gh pr create --base main --title "Add about page" --body "…"
gh pr create --fill       # use your commit messages as title and body
gh pr create --web        # open the form in the browser
  1. Check the base (where it will be merged — usually main) and the compare branch (yours).

Writing a good description

Reviewers read the description first. Make their job easy:

MARKDOWN
## What
Adds an About page introducing the site's author.

## Why
Visitors asked who runs the site. Closes #12.

## How to test
1. Open about.html
2. Check the heading and introduction render correctly

## Screenshots
(before/after images for visual changes)
  • Title: short and specific, like a good commit subject.
  • What and why: the code shows how; the description explains the purpose and any decisions.
  • Links: Closes #12 links the issue and closes it automatically when the PR is merged (Issues and projects).
  • How to test: steps a reviewer can follow.

Templates

Add .github/pull_request_template.md to the repository and every new PR starts with its contents — a consistent structure, plus a checklist. (GitHub also accepts the file in the repository root or in docs/, and a PULL_REQUEST_TEMPLATE/ folder for several templates.)

Draft pull requests

Open a PR as a draft when the work isn’t finished but you want to share it — for early feedback, or to see the CI results:

Terminal
gh pr create --draft
gh pr ready              # later: mark it ready for review

Drafts can’t be merged and don’t request reviews until they’re marked ready.

Keep pull requests small

Small PRs get reviewed faster and more thoroughly, cause fewer conflicts, and are easier to revert. Aim for one purpose per PR — a few hundred changed lines at most. If a feature is big, split it into a series of PRs that each leave main working (feature flags help hide unfinished functionality).

Updating a pull request

A PR tracks its branch, not a fixed set of commits. To respond to feedback, commit and push to the same branch — the PR updates automatically:

Terminal
git commit -am "Address review: use semantic heading"
git push

If main has moved on and the PR conflicts or is out of date:

Terminal
git fetch
git rebase origin/main          # then: git push --force-with-lease
# or
git merge origin/main           # then: git push

GitHub’s “Update branch” button does the merge (or rebase) for you when there are no conflicts.

Checks and reviews

Before merging, a PR usually needs:

  • Status checks — automated tests from GitHub Actions or other CI (chapter 10). Their results appear at the bottom of the PR. gh pr checks shows them in the terminal.
  • Reviews — at least one teammate approving the change (next lesson).

Repository rules can make both mandatory (Protecting branches).

Merging

When everything is green, someone with write access merges the PR. There are three methods; the repository’s Settings → General → Pull Requests decides which buttons appear:

Method Result on main Good for
Create a merge commit all PR commits + a merge commit keeping full branch history
Squash and merge one new commit containing all changes a clean history of one commit per PR
Rebase and merge PR commits replayed individually, no merge commit linear history with meaningful individual commits
Terminal
gh pr merge --squash --delete-branch
gh pr merge --auto --squash      # merge automatically once checks and reviews pass

After merging, delete the branch (GitHub can do this automatically: Settings → Automatically delete head branches), and update your local main:

Terminal
git switch main
git pull
git branch -d feature/about-page    # may need -D after a squash merge

That last note is worth understanding: after a squash merge, main contains a new commit, not your branch’s commits — so Git doesn’t consider your local branch merged, and -d refuses. Since the PR is merged on GitHub, -D is safe.

Pull requests between forks

You can also open a PR from your copy (fork) of someone else’s repository — the standard way to contribute to open source. Forks and contributing covers it.

A good PR is a gift to the reviewer: small, focused, described, tested, and with a clean diff. You’ll get faster, better reviews in return.

Exercise

Your first pull request

In your practice repository on GitHub, create a branch feature/about-page, add an about.html page in two commits, push it, and open a pull request against main with a clear title and a description that explains what and why and how to test it. Open it as a draft first, then mark it ready for review. Add a pull request template to the repository so future PRs start with the same headings. Finally, squash-merge it and delete the branch.

Terminal
# Run inside your practice repository from the previous lesson (with gh signed in)
git switch main && git pull

# 1. Branch and two commits

# 2. Push and open a draft PR with a good description

# 3. Mark it ready for review

# 4. Squash-merge and delete the branch

# 5. Add a PR template for next time (on its own branch + PR, or directly if you're alone)

Summary

  • A pull request (PR) asks to merge one branch into another, with discussion, review and checks in one place.
  • Good PRs are small and focused, with a title and description that say what changed, why, and how to test it.
  • Open a draft PR to share early work; mark it ready when you want review.
  • Push more commits to the same branch to update a PR; keep it current with main by rebasing or merging.
  • Merge with a merge commit, a squash or a rebase — the repository settings decide which are allowed.