Pull Requests

8 min

Table of contents


1 — What is a pull request?

A pull request (PR), also called a merge request on GitLab, is an integration request: “here is my work on a branch, please review it then merge it into main”. It is the meeting point between the code and the team.

A PR is not just a “merge” button. It is a discussion space around the code: comments, suggestions, automated tests, validation. That is where quality is decided.

A PR is used to…In practice
Have the code reviewedA colleague spots bugs and improvements
Trigger CIAutomated tests + build on the branch
Document the changeTitle + description explain the “why”
Trace the decisionWho approved, when, why

↑ Back to top


2 — Create a pull request

Before opening a PR, you must have pushed your branch to GitHub.

Step 1 — Push the branch:

bash
git switch feature/recherche
git push -u origin feature/recherche

Step 2 — Open the PR (two options):

  • On the GitHub interface: a “Compare & pull request” banner appears; you click, you choose the base branch (main) and the compare branch (feature/recherche).
  • On the command line with GitHub CLI:
bash
# Create the PR without leaving the terminal
gh pr create --base main --head feature/recherche \
  --title "Add search" \
  --body "Implements the search bar with filters."

A good PR description contains:

SectionContent
WhatWhat the PR does in one sentence
WhyThe problem or need it solves
How to testSteps to verify
LinkNumber of the related issue (e.g. Closes #42)

The title and description are read by busy humans. Be explicit: “Fix the crash on login” is a thousand times better than “fix bug”.

🔧 Mini-exercise — From the current branch feature/recherche, create a pull request toward main with gh, giving a clear title.

✅ See a solution
bash
gh pr create --base main --head feature/recherche \
  --title "Add search" --body "Implements the search bar."

↑ Back to top


3 — Code review

Code review is the heart of the PR: one or more colleagues read the changes, ask questions, suggest improvements, and end up approving or requesting changes.

The three possible verdicts on GitHub:

VerdictMeaning
ApproveThe code is good, we can merge
Request changesCorrections are needed before merge
CommentRemarks without blocking or approving

On the author's side, after comments, you fix and push again: the PR updates automatically.

bash
# Fix after the review
git switch feature/recherche
# ... changes ...
git commit -am "Address review feedback"
git push          # the PR updates on its own

What a good reviewer looks at:

  • Does the code do what it claims? (correct logic)
  • Is it readable and maintainable?
  • Are there tests? Does CI pass green?
  • Any security or performance issues?

Code review is not a judgment of the person, but a collective improvement of the product. You criticize the code, never the author. And you also highlight what is well done.

↑ Back to top


4 — Merge a pull request

Once the PR is approved and CI is green, you merge it. GitHub offers three methods, which change the shape of the history.

MethodWhat it doesWhen to use it
Create a merge commitCreates a merge commit, keeps every commit of the branchTrace the entire branch
Squash and mergeSquashes every commit into one clean commitClear, concise main history
Rebase and mergeReplays the commits onto main, without a merge commitStrictly linear history
bash
# Merge from the terminal with GitHub CLI
gh pr merge 42 --squash --delete-branch

After the merge, you clean up:

bash
# Delete the remote branch (often automatic)
git push origin --delete feature/recherche

# Update your local
git switch main
git pull origin main

# Delete the local branch
git branch -d feature/recherche

Squash and merge is very popular: one feature = one clean commit in main. The history becomes a readable list of features, not a mess of “wip”, “fix typo”, “oops”.

🔧 Mini-exercise — With gh, merge PR number 42 as a squash and delete the branch in the same step. Write the command.

✅ See a solution

gh pr merge 42 --squash --delete-branch

↑ Back to top


5 — PR good practices

An effective PR is a small, clear, and tested PR. Here are the habits of high-performing teams.

Good practiceWhy
Small PRs (< 400 lines)Easier and faster to review
One PR = one topicNo mix of “feature + refactor + typo”
Clear title + descriptionThe reviewer understands without guessing
Link the issue (Closes #N)Traces the need and closes the issue on merge
Green CI before asking for reviewYou do not have broken code reviewed
Answer every commentNothing stays unanswered
bash
# Automatically link an issue in the description
gh pr create --title "Add CSV export" \
  --body "Allows exporting the data as CSV. Closes #57"

A 1,000-line PR gets an “LGTM” (looks good to me) without a real review — nobody has the courage to read everything. A 50-line PR gets valuable feedback. Small = reviewed seriously.

🔧 Mini-exercise — Which keyword do you add in a PR description to automatically close issue #57 on merge?

✅ See a solution

Closes #57 (the variants Fixes #57 or Resolves #57 also work).

↑ Back to top


6 — Quiz — Pull requests

Question 1: What is a pull request for?

a) Deleting a branch

b) Asking for the review and integration of one branch into another

c) Installing Git

d) Cloning a repository

See the solution

Answer: b) — A PR asks for the review of a branch's code then its merge (often into main).


Question 2: What must you do before you can open a PR on GitHub?

a) Delete main

b) Push your branch to the remote repository (git push)

c) Close the terminal

d) Disable CI

See the solution

Answer: b) — The branch must exist on the remote side; you push it with git push -u origin branch-name.


Question 3: What does “Request changes” mean during a review?

a) The code is approved

b) Corrections are needed before the merge

c) The PR is deleted

d) A new repository is created

See the solution

Answer: b) — The reviewer asks for modifications; the author fixes and pushes again, which updates the PR.


Question 4: Which merge method squashes every commit of the branch into one?

a) Create a merge commit

b) Squash and merge

c) Rebase and merge

d) Cherry-pick

See the solution

Answer: b)Squash and merge condenses every commit into one clean commit in main.


Question 5: Why prefer small pull requests?

a) They use less disk

b) They are reviewed faster and more seriously

c) GitHub makes them mandatory

d) They avoid writing tests

See the solution

Answer: b) — A small PR is reviewed carefully and quickly; a huge PR often gets an “LGTM” without a real review.

↑ Back to top


7 — Practice — Open and merge a PR

Instructions

You have finished a feature on the branch feature/footer. Complete the full cycle of a pull request with GitHub CLI (gh):

  1. Push the branch.
  2. Open a PR toward main with a clear title and an issue link (Closes #12).
  3. Once approved, merge it as a squash and delete the branch.
  4. Update your local repository.

Correction

bash
# 1. Push the branch
git switch feature/footer
git push -u origin feature/footer

# 2. Open the pull request
gh pr create --base main --head feature/footer \
  --title "Add the site footer" \
  --body "Adds a responsive footer with links and legal notices. Closes #12"

# 3. After approval: squash merge + delete the branch
gh pr merge --squash --delete-branch

# 4. Update local
git switch main
git pull origin main
git branch -d feature/footer

Expected result:

StepVerification
PR createdgh pr list shows the PR open toward main
Issue linkedThe description contains Closes #12 (will close the issue on merge)
Squash mergeA single commit “Add the site footer” appears in main
Branch deletedgit branch no longer lists feature/footer
text
$ git log --oneline -1
a1b2c3d Add the site footer (#13)

The number in parentheses (#13) is added automatically by GitHub: it is the PR number. Clicking it brings you back to the entire review discussion. Full traceability.

↑ Back to top


8 — Summary

Key takeaways

  1. A pull request asks for the review then the merge of a branch: it is a discussion space.
  2. Create a PR: push the branch, then open it via the interface or gh pr create.
  3. Code review ends in Approve, Request changes, or Comment; you criticize the code, not the author.
  4. Three merge methods: merge commit, squash and merge, rebase and merge.
  5. Good practices: small PRs, one topic, green CI, linked issue.
  6. After merge: delete the branch and update your local.

What's next

You master the contribution cycle on your repository. Lesson 04 — Collaborative workflow opens wider collaboration: fork, clone, issues, and team good practices.

↑ Back to top


All rights reserved. Any reproduction, distribution, use or adaptation of this course, in whole or in part, is strictly prohibited without the prior written authorization of Dr. Haythem REHOUMA.

Course created by Dr. Haythem REHOUMA — Development and Deployment of Data Solutions