| # | Section |
|---|---|
| 1 | What is a pull request? |
| 2 | Create a pull request |
| 3 | Code review |
| 4 | Merge a pull request |
| 5 | PR good practices |
| 6 | Quiz — Pull requests |
| 7 | Practice — Open and merge a PR |
| 8 | Summary |
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 reviewed | A colleague spots bugs and improvements |
| Trigger CI | Automated tests + build on the branch |
| Document the change | Title + description explain the “why” |
| Trace the decision | Who approved, when, why |
Before opening a PR, you must have pushed your branch to GitHub.
Step 1 — Push the branch:
git switch feature/recherche
git push -u origin feature/rechercheStep 2 — Open the PR (two options):
main) and the compare branch (feature/recherche).# 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:
| Section | Content |
|---|---|
| What | What the PR does in one sentence |
| Why | The problem or need it solves |
| How to test | Steps to verify |
| Link | Number 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.
gh pr create --base main --head feature/recherche \
--title "Add search" --body "Implements the search bar."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:
| Verdict | Meaning |
|---|---|
| Approve | The code is good, we can merge |
| Request changes | Corrections are needed before merge |
| Comment | Remarks without blocking or approving |
On the author's side, after comments, you fix and push again: the PR updates automatically.
# Fix after the review
git switch feature/recherche
# ... changes ...
git commit -am "Address review feedback"
git push # the PR updates on its ownWhat a good reviewer looks at:
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.
Once the PR is approved and CI is green, you merge it. GitHub offers three methods, which change the shape of the history.
| Method | What it does | When to use it |
|---|---|---|
| Create a merge commit | Creates a merge commit, keeps every commit of the branch | Trace the entire branch |
| Squash and merge | Squashes every commit into one clean commit | Clear, concise main history |
| Rebase and merge | Replays the commits onto main, without a merge commit | Strictly linear history |
# Merge from the terminal with GitHub CLI
gh pr merge 42 --squash --delete-branchAfter the merge, you clean up:
# 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/rechercheSquash 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.
gh pr merge 42 --squash --delete-branch
An effective PR is a small, clear, and tested PR. Here are the habits of high-performing teams.
| Good practice | Why |
|---|---|
| Small PRs (< 400 lines) | Easier and faster to review |
| One PR = one topic | No mix of “feature + refactor + typo” |
| Clear title + description | The reviewer understands without guessing |
Link the issue (Closes #N) | Traces the need and closes the issue on merge |
| Green CI before asking for review | You do not have broken code reviewed |
| Answer every comment | Nothing stays unanswered |
# 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?
Closes #57 (the variants Fixes #57 or Resolves #57 also work).
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
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
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
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
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
Answer: b) — A small PR is reviewed carefully and quickly; a huge PR often gets an “LGTM” without a real review.
You have finished a feature on the branch feature/footer. Complete the full cycle of a pull request with GitHub CLI (gh):
main with a clear title and an issue link (Closes #12).# 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/footerExpected result:
| Step | Verification |
|---|---|
| PR created | gh pr list shows the PR open toward main |
| Issue linked | The description contains Closes #12 (will close the issue on merge) |
| Squash merge | A single commit “Add the site footer” appears in main |
| Branch deleted | git branch no longer lists feature/footer |
$ 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.
gh pr create.You master the contribution cycle on your repository. Lesson 04 — Collaborative workflow opens wider collaboration: fork, clone, issues, and team good practices.
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