Pull requests

Beginner · 4 min

A pull request asks to merge one branch into another and gives the team a place to review and test first. Learn what it contains and how to write one.

Before thisCreating and switching branchesUpstream tracking branchesCreating and publishing a repositoryFeature branches and Gitflow

GitHub · 4 min

Pull requests

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by GitHubReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A pull request is not a Git feature but a GitHub one: a request to merge a head branch into a base branch, with a conversation and automated checks attached.
  • The Files changed tab shows the three-dot diff, the changes on your branch since it diverged from the base, not the differences between the two branch tips.
  • A good pull request is small, has a title that says what changed, and a description that says why and how to check it.
  • A draft pull request signals that work is not ready to merge, so you can ask for early feedback without risking a premature merge.
  • Writing Closes #12 in the description links the pull request to an issue and closes it when the pull request merges into the default branch.

The problem a pull request solves

On your own you can merge a branch whenever you like. On a team, someone else will run the code, and someone else’s work might clash with yours. You need a step between “I finished this” and “this is on main”, where other people can look, ask questions and run checks.

A pull request (PR) is that step. It is a GitHub feature, not a Git one. Git has no concept of it. A PR says: here is branch add-tag-filter, please merge it into main. GitHub attaches a conversation, a list of commits, a diff, and the results of automated checks to that request. When people are happy, the merge happens from the PR page.

The two branches have names. The head (or compare) branch holds your changes. The base branch is where they will land.

The flow for the notes project

git switch -c add-tag-filter
# edit, test, commit
git push -u origin add-tag-filter

After the push, GitHub offers a Compare & pull request banner on the repository page. Click it, check that base is main and compare is your branch, write a title and description, and click Create pull request. If the work is not ready, use the drop-down on that button to choose Create draft pull request instead.

I could not drive this part of the UI, as I have no GitHub account in the environment where I wrote the lesson. The steps and labels come from GitHub’s “Creating a pull request” page, which I read on 2026-11-23. The same page notes that a PR can only be opened between two different branches, and that without write access to the repository you need to fork it first, which is the subject of forks and multiple remotes.

What the diff shows

This trips people up. Suppose you branched from main, then main gained a new commit that you do not have. If the PR page compared the two branch tips directly, main’s new change would look like something you deleted.

It does not. The Files changed tab shows the changes on your branch since it diverged from the base, which Git calls the three-dot diff. I reproduced the difference in a scratch repository: main had one extra file, and my branch added tags.mjs.

git diff --stat main...add-tags   # tags.mjs | 1 +            (what the PR shows)
git diff --stat main..add-tags    # m | 1 -   and   tags.mjs | 1 +

The two-dot form listed m as a deletion, which it is not, while the three-dot form listed only my file. git log --oneline main..add-tags showed just my one commit. When you want to preview locally what a reviewer will see, use main...your-branch.

One more fact, which I checked only partly. GitHub also keeps each PR’s commits reachable under a special ref, refs/pull/<number>/head, so you can fetch someone’s PR without adding their fork: git fetch origin pull/1/head:pr-1. I simulated the mechanism by creating that ref by hand in a local bare repository and fetching it, which worked. I did not fetch a real PR.

Writing one that gets reviewed

Reviewers are people with limited attention. A few habits make a large difference.

  • Keep it small. A PR is easiest to review when it does one thing. Past a few hundred changed lines, reviewers skim.
  • Title it as a result. “Add –tag filter to list” beats “Update cli.mjs”.
  • Explain why. The diff shows what changed. The description should say why, what you decided not to do, and how someone can check it works.
  • Link the issue. Writing Closes #12 in the description links the PR to issue 12 and closes it when the PR merges. Accepted keywords are close, closes, closed, fix, fixes, fixed, resolve, resolves and resolved. For an issue in another repository use Fixes octo-org/octo-repo#100. This only works when the PR targets the default branch. I read this in the docs on 2026-11-23 and could not test it.
  • Use draft PRs. If you want early feedback on direction, open a draft. It cannot be merged until you mark it ready, which prevents the “I just wanted a quick look” accident.

Once the PR is open, keep working on the same branch. Each push adds commits to the PR and re-runs its checks, with no need to open another.

What happens on the page

The PR page has three tabs you will use constantly. Conversation holds the description, comments and events. Commits lists the commits on the head branch. Files changed is the diff, where review comments are added. Below the conversation you see the status of checks, such as the tests you will set up in the GitHub Actions group, and whether the branch can be merged cleanly. If it conflicts with the base, you resolve it with the same tools as in resolving merge conflicts, then push.

Reviews are the next lesson, and the merge button is the lesson after that.

What the video covers

GitHub’s “How to create a pull request in 4 min | GitHub for Beginners” is under four minutes and was published around 2024. The description says you will create a pull request, suggest changes to a repository and have others review them before merging. It is a short, official walkthrough of the click path. I could not read a transcript, so I do not know whether it works on a fork or a branch. English is judged from the title and the channel. It is the shortest video in this group, so it covers the click path and not the habits above, which is why they are on this page.

Where this fits

A PR exists to be reviewed. How to give and receive review comments on GitHub is next: code review on GitHub.

Check yourself

  1. 01What are the head and base branches of a pull request?

    The head (or compare) branch holds your changes. The base branch is where you want them merged, usually main.

  2. 02Main has moved on since you branched. Does the pull request diff show main's new changes as deletions?

    No. The pull request diff compares your branch against the point where it diverged from main, the three-dot form, so only your own changes appear.

  3. 03After you push more commits to the same branch, what happens to the open pull request?

    It updates automatically. The new commits join the pull request, and checks run again. You do not open a second one.

  4. 04When does a Closes keyword in a pull request description actually close the issue?

    When the pull request targets the repository's default branch and is merged. On any other target branch the keyword is ignored.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark