Basic

A pull request is just a conversation

A pull request (PR) is how you ask your teammates to look over your branch before it joins main. It turns a private edit into a shared moment, everyone can see what changed, why, and weigh in. On GitHub it's the normal way teams review each other's work.

What you will see

Merging squash merge of #1 into main The branch was deleted and synced.

About 2 min of reading

Quick check

Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.

Try It

A pull request turned a private edit into a shared moment, and the first one I opened I did not know how to finish. Let me do the part I control locally, the branch, the diff a reviewer will see, responding to a comment, then open and merge it on GitHub so the whole conversation has somewhere to live.

1

Open a pull request, but first put something worth reviewing on a branch. This makes a change on a feature branch while main stays clean. The reviewer will see exactly this diff against main, so it should be one small, self-contained edit, the kind of thing easy to read in a browser.

git switch -c feature/login echo "login form" > login.html git add login.html git commit -m "Add login form"

Before you run it, say out loud what it will print. Then open the answer.

What it prints
[feature/login def4567] Add login form 1 file changed, 1 insertion(+)
The branch holds the change, not main. If I committed on main, there would be nothing for a pull request to show, a PR can only compare one branch against another.
2

Before opening anything, look at the exact diff the reviewer will see. The three dots in main...feature/login compare what the branch adds to main, not the whole history. This is the preview I take a screenshot of before I ask anyone to read it.

git diff main...feature/login

Before you run it, say out loud what it will print. Then open the answer.

What it prints
diff --git a/login.html b/login.html +login form
Two dots (main...feature) is a common typo; with two dots git compares the tip of main against the working tree of the branch. Three dots is the real review diff: every commit the branch is missing.
3

Open the pull request on GitHub. This is the moment the edit becomes shared, the page shows the diff, a field for what changed and why, and a button to request reviewers. I paste a short note explaining the change, and the conversation starts.

gh pr create --title "Add login form" --body "Builds the login page on its own branch."

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Creating pull request for feature/login into main https://github.com/ada/myapp/pulls/1
gh is the GitHub command-line tool. If it is not installed or is not signed in to the right account, open the pull request by hand in the browser under the Pull requests tab.
4

A reviewer comments: please rename a variable so it means more. I reply right here on the branch by editing the file and committing again, without touching main. Every change I make on the branch shows up in the same pull request, so the reviewer sees it the moment I push.

sed -i "s/"d":/"userData":/" app.js git add app.js git commit -m "Rename d to userData" git push

Before you run it, say out loud what it will print. Then open the answer.

What it prints
To https://github.com/ada/myapp.git def4567..abc9876 feature/login -> feature/login
Do not open a second pull request for this. It is still the same branch, so the update lands in the existing request and keeps the whole conversation in one place.
5

The reviewer approves and merges. The branch joins main, the pull request closes as merged, and the history now shows exactly what shipped. This is the end of the conversation, the code is in, the request is done.

gh pr merge 1 --squash --delete-branch

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Merging squash merge of #1 into main The branch was deleted and synced.
Use squash (or rebase) so the merge stays one clean commit, not ten. A merge request is the final approval; once it runs the branch is no longer needed.

Put it in order

Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.

Data Flow

Open a PR, let others review it, fix anything they flag, then merge.
1 Open a PR
↓
2 Others review it
↓
3 Fix the notes
↓
4 Merge to main
Why this works
Review before you merge

A PR gives others a chance to check your work. Good reviewers ask questions and catch mistakes before they go live, they're doing you a favor, not nitpicking.

Merging

Once it's approved, the branch merges into main and the new work becomes part of the project. The request is done, and the history now shows exactly what shipped.

Examples

The whole PR cycle in a few lines

You: "Open pull request: add login page."
Reviewer: "Looks good! One small change here."
You: "Fixing it now."
Reviewer: "Approved. Merging."

A PR keeps that whole back-and-forth in one place, tied to the actual code. Nobody has to describe the change over chat, everyone can read exactly what changed and leave their comments next to the relevant line.

Reviewing someone else's work

Great start here.
Can we add a short comment on line 12?
Looks good to me. Approving.

A reviewer reads the changes and leaves comments: questions, suggestions, or a plain approval. It's meant to keep the code healthy, not to score points. Every comment is a chance to learn something about how a teammate would handle a similar problem.

Asking for changes, gently

Please rename this variable.
"userData" tells me more than "d".

When something isn't right, you request changes, which pauses the merge until it's fixed. It's a normal, polite part of the process, it just says "here's what to fix before this can merge". Being specific about what and why saves the author a guess.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Why you never work directly on main
Previous Lesson
Why you never work directly on main
Next Lesson
What a conflict actually is (and why it isn't a disaster)
What a conflict actually is (and why it isn't a disaster) →