What is a Pull Request (PR) and what is it for? A simple guide with practical examples

   

In the world of modern software development, working as a team on the same project can feel a bit like cooking in a crowded kitchen: if everyone gets their hands in the same dish at the same time, the risk of making a mess is extremely high.

To avoid chaos, conflicts, and "burnt" code, developers use version control tools like Git and platforms like GitHub, GitLab, or Bitbucket. At the heart of this workflow is a fundamental concept: the Pull Request (or Merge Request).

But what exactly is it and what is its purpose? Let's find out together using simple language and a practical example.

🔗 Do you like Techelopment? Check out the website for all the details!

1. Culinary Metaphor: The Family Recipe Book

Imagine you want to add your secret chocolate cake recipe to a famous digital recipe book written together with your friends.

  • You can't just jump into the central system and modify the official book, risking ruining the existing pages (Master branch or main branch).
  • Instead, you take a photocopy of the book, go to your private kitchen (Branch or development branch), experiment with your recipe, and perfect it.
  • Once the cake turns out perfect, you go back to your friends with your written page and say: "Hey, I wrote this new recipe, pull my changes into the main book after checking it.".

There you go: this request for review and integration is, simply put, a Pull Request.


2. Technical Definition: What is a Pull Request?

From a technical standpoint, a Pull Request (PR) is a proposed code modification.

When a programmer wants to add a new feature, fix a bug, or improve a part of software, they don't directly modify the official source code. Instead, they follow these steps:

  1. Create an isolated copy of the code (Branch).
  2. Make the necessary changes on that copy.
  3. Open a Pull Request on the hosting platform (e.g., GitHub) to ask colleagues to review the work before merging (Merge) it with the project's main branch.

3. What is its purpose? The 4 fundamental pillars

A Pull Request is not just a "button to merge code," but a powerful tool for several reasons:

  • Code Review: Other developers can read the lines of code written, suggest improvements, find careless errors, or security flaws before they go into production.
  • Teamwork: It facilitates asynchronous collaboration. Even if programmers work in different time zones, anyone can comment on and approve others' work.
  • Documentation and History: Every PR tells a story. It explains why a change was made, what problems it solves, and who approved it, creating a valuable history for the future.
  • Automated Testing (CI/CD): Many systems automatically run tests on the PR's code to verify that nothing has broken even before a human starts reading it.

4. A step-by-step practical example

Let's imagine we work for a company that runs an e-commerce site. Our task is to add the "Add to Wishlist" button on the product page.

Step 1: Creating the Branch

Instead of working on the live site, we create a working copy called feature/add-wishlist-button.

Step 2: Writing the Code

We write the HTML, CSS, and JavaScript code needed to make the heart icon appear on the product page. We test everything locally and, when we are satisfied, we upload the changes to GitHub.

Step 3: Opening the Pull Request

On GitHub, we click the "New Pull Request" button. We fill out a form with:

  • Title: Added "Add to Wishlist" button to the product page
  • Description: This update allows registered users to save their favorite products in their personal area. I tested the layout on desktop and mobile.

Step 4: The Review

The Lead Developer or a colleague receives the PR notification. They read the code and notice a detail:

"Great job! I just wanted to point out that on the mobile version, the heart icon overlaps the price. Can you fix the CSS margin?"

Step 5: Updating and Merging

We quickly modify the CSS and upload the change again (it will automatically update in the same PR). The colleague sees that everything looks good, clicks "Approve" and finally "Merge".

The code officially enters the main software: the feature is ready to be published online!


Summary

Without Pull Request With Pull Request
Direct and chaotic changes to the code Isolated and safe changes
No preventative checks (bug risk) Collective code review (Code Review)
Difficult to trace back errors Clear and traceable history of every modification



Follow me #techelopment

Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment