Skip to main content
GitHub Flow
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 the main 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 main branch).

4. Anatomy of a Pull Request

When you open a PR on GitHub, it creates a dedicated webpage that shows exactly three things:
  1. 1. The Conversation Tab: A timeline of comments, reviews, and automated test results.
  1. 2. The Commits Tab: A list of the specific Git snapshots included in this branch.
  1. 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. 1. Navigate to your repository on github.com.
  1. 2. Because you recently pushed a branch, GitHub will display a yellow banner at the top saying: "feature/dark-mode-toggle had recent pushes."
  1. 3. Click the green Compare & pull request button next to it.
  1. 4. Fill out the form:
  • Ensure the "base" branch is main and the "compare" branch is your feature branch.
  • Write a title: "Add Dark Mode Teaser".
  • Write a short description explaining you updated the README.
  1. 5. Click Create pull request.
  1. 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.
  1. 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. 1. What three primary pieces of information should be included in a professional Pull Request description?
  1. 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 pristine main branch.

12. Summary

In Chapter 4, we explored the cornerstone of collaborative software development: The Pull Request. We transitioned from writing isolated code to formally proposing its integration into the production codebase. We learned how to articulate the purpose of our changes through professional PR descriptions, simplifying the task for our reviewers. We demystified the Code Review process, understanding it not as a critique of our abilities, but as a critical quality-assurance gateway. Finally, we executed a successful merge, completing the lifecycle of our feature branch.

13. Next Chapter Recommendation

A Pull Request requires reviewers. How do we effectively assign tasks, communicate, and coordinate these reviews with our teammates? Proceed to Chapter 5: Collaboration and Team Workflows.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·