CHAPTER 04
Pull Requests Fundamentals
Updated: May 15, 2026
20 min read
# CHAPTER 4
Pull Requests Fundamentals
1. Introduction
You have written the code, committed it to your feature branch, and pushed it to GitHub. What happens next? You do not simply smash your code into themain branch. You must open a gateway for peer review, discussion, and automated testing. This gateway is the Pull Request (PR). The Pull Request is the beating heart of GitHub Flow. It is not a Git command; it is a collaborative interface built by GitHub. In this chapter, we will learn how to create a professional Pull Request, understand the mechanics of Code Review, and navigate the process of getting our code approved and merged.
2. Learning Objectives
By the end of this chapter, you will be able to:- Define what a Pull Request is and why it is essential.
- Create a Pull Request via the GitHub interface.
- Write a professional Pull Request description.
- Understand the mechanics of peer Code Review.
- Execute a Pull Request Merge.
3. Beginner Explanation
Imagine you are a journalist writing an article for a major newspaper.- The Draft (Your Branch): You write the article on your laptop. It's good, but you might have made a typo, or your facts might be slightly wrong.
- The Editor's Desk (The Pull Request): You don't have the power to just print the newspaper yourself. You submit your draft to the Editor's desk.
- The Review (Code Review): The Editor reads it with a red pen. They leave a note: "Change this word in paragraph 2."
- The Revision (Pushing more commits): You change the word on your laptop and hand it back to the Editor.
-
Publishing (The Merge): The Editor says "Perfect!" and presses the button to print it in the official newspaper (the
mainbranch).
4. Anatomy of a Pull Request
When you open a PR on GitHub, it creates a dedicated webpage that shows exactly three things:- 1. The Conversation Tab: A timeline of comments, reviews, and automated test results.
- 2. The Commits Tab: A list of the specific Git snapshots included in this branch.
-
3.
The "Files Changed" Tab: The
git diff. It shows the exact lines of code added (in green) and deleted (in red). This is where reviewers spend all their time.
5. Writing a Professional PR Description
A PR titled "Update" with no description is unacceptable. The reviewer has no idea what they are looking at. A good PR tells a story.- Title: State clearly what the PR does (e.g., "Add User Authentication via JWT").
- Description:
- What: What does this code do?
- Why: Why is this change necessary? (Link to a bug report or ticket).
- How to Test: Give the reviewer step-by-step instructions on how to test your code locally to prove it works.
6. Mini Project: Submit First Pull Request
Let's merge the branch we created in the last chapter.Step-by-Step Walkthrough:
-
1.
Navigate to your repository on
github.com.
- 2. Because you recently pushed a branch, GitHub will display a yellow banner at the top saying: "feature/dark-mode-toggle had recent pushes."
- 3. Click the green Compare & pull request button next to it.
- 4. Fill out the form:
-
Ensure the "base" branch is
mainand the "compare" branch is your feature branch.
- Write a title: "Add Dark Mode Teaser".
- Write a short description explaining you updated the README.
- 5. Click Create pull request.
- 6. *The Result:* You have successfully submitted your code for review! In a real team, you would now wait for a coworker to approve it.
- 7. For this exercise, click the green Merge pull request button yourself, then click Confirm merge.
7. Code Review Basics
Code Review is the process where a senior developer (or a peer) reads your code before it is merged. They will navigate to the "Files Changed" tab in your PR. If they see a mistake, they can click on the exact line of code and leave a comment: "This variable name is confusing, please change it." How to respond: You do not close the PR! You simply go back to your local terminal, change the variable name, save it,git commit, and git push. The PR on GitHub will automatically update with your new commit, and the reviewer can see you fixed it.
8. Best Practices
-
Self-Review First: Before you click "Create pull request," you should click the "Files Changed" tab and read your own code. Developers frequently catch their own typos or realize they left
console.log("testing123")in their code just by taking 60 seconds to review their own diff.
9. Common Mistakes
- Taking Code Review Personally: When a senior developer leaves 15 comments on your PR telling you to rewrite your code, it is not an insult to your intelligence. Code review is a collaborative process designed to catch bugs and share knowledge. Drop your ego. Embrace the feedback as free mentorship.
10. Exercises
- 1. What three primary pieces of information should be included in a professional Pull Request description?
- 2. If a reviewer asks you to change a line of code in your Pull Request, what exact steps do you take on your local machine to update the PR?
11. FAQs
Q: Do I need to be on a team to use Pull Requests? A: No! Many solo developers use Pull Requests for their own personal projects. It acts as a final checklist and allows them to review their own code in a clean interface before merging it into their pristinemain branch.