Pull Requests Fundamentals

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 9 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Lesson: Pull Request Fundamentals

Introduction: The Heart of Modern Collaboration

In the world of software development, writing code is rarely a solitary endeavor. Whether you are working on an open-source project with contributors from across the globe or building a product within a corporate engineering team, the ability to integrate your work with others is critical. This is where the Pull Request (PR) comes into play. A Pull Request is the fundamental mechanism used in platforms like GitHub to notify your team members that you have completed a set of changes and are ready for them to review your work.

Why does this matter? Without a structured way to propose changes, development would be chaotic. If everyone pushed code directly to the main production branch, the history would become a tangled mess of broken builds and conflicting logic. Pull Requests provide a formal space to discuss, review, and refine code before it ever touches the primary codebase. They act as a gateway for quality control, documentation, and knowledge sharing. By mastering the Pull Request workflow, you move from being a developer who just writes code to a collaborative engineer who improves the overall health of the project.

In this lesson, we will explore the lifecycle of a Pull Request, from the moment you push your branch to the final merge. We will look at how to structure your work, how to participate in reviews, and how to maintain a clean project history.

Not read yet

Understanding the Pull Request Workflow

At its core, a Pull Request is a request to merge one branch into another. Typically, this involves merging a feature branch (where you have been working on a specific task) into a primary branch, such as main or develop. The platform hosting your repository creates a visual interface that highlights the differences between these two branches, commonly known as a "diff."

Callout: Pull Request vs. Merge Request You might hear the terms "Pull Request" (used by GitHub) and "Merge Request" (used by GitLab) interchangeably. While the branding differs, the underlying concept is identical: a request to review and integrate changes from one branch into another. Both tools offer similar features for commenting, code review, and automated testing.

The workflow generally follows these distinct stages:

  1. Branching: You create a new branch from the latest version of the target branch.
  2. Developing: You perform your work and commit changes to your local branch.
  3. Pushing: You push your local branch to the remote repository on GitHub.
  4. Opening: You open a Pull Request through the GitHub web interface.
  5. Reviewing: Your teammates provide feedback, request changes, or approve the PR.
  6. Refining: You address feedback by pushing additional commits to the same branch.
  7. Merging: Once approved, the changes are merged into the target branch.

Each of these steps serves a specific purpose in ensuring that the final output is high-quality and free of regressions.

Not read yet

Step-by-Step: Creating Your First Pull Request

To start, ensure you have a local environment set up with Git and a repository hosted on GitHub. Let’s assume you are tasked with adding a new feature.

1. Preparing the Branch

Never work directly on your main branch. Always create a dedicated branch for your specific task. This keeps your workspace clean and allows you to work on multiple features simultaneously if needed.

# Ensure you are on the latest main
git checkout main
git pull origin main

# Create and switch to a new branch
git checkout -b feature/user-authentication

2. Committing Changes

Make your changes to the code. Once you are satisfied, stage and commit them. Be descriptive in your commit messages. A good commit message explains why you made a change, not just what you changed.

# Stage your files
git add auth.js login.html

# Commit with a clear message
git commit -m "Add basic email and password validation logic"

3. Pushing to GitHub

Push your local branch to the remote repository.

git push origin feature/user-authentication

4. Opening the PR on GitHub

Navigate to your repository on GitHub. You will usually see a yellow bar at the top of the repository page suggesting that you open a Pull Request for your recently pushed branch. Click "Compare & pull request."

Fill out the form with a clear title and a description. The description is crucial. It should explain the problem you are solving, the approach you took, and any instructions for the reviewer on how to test your code.

Tip: Use PR Templates If you find yourself writing the same information in every PR description, use a GitHub PR template. By adding a .github/pull_request_template.md file to your repository, GitHub will automatically populate the PR description field with your chosen structure, ensuring consistency across the team.

Not read yet

Best Practices for Effective Pull Requests

A Pull Request is an act of communication. If you want your code to be merged quickly, you need to make it as easy as possible for your reviewers to understand and verify your work.

Keep PRs Small and Focused

The most common mistake developers make is submitting "mega-PRs"—changes that span dozens of files and hundreds of lines of code. These are difficult to review, prone to bugs, and often take weeks to get through the review process. Aim for PRs that address a single, small feature or bug fix. If you have a large feature, break it down into smaller, logical pieces that can be merged independently.

Write Descriptive Titles and Descriptions

Reviewers should not have to guess what your PR does.

  • Bad Title: "Update files"
  • Good Title: "Fix: Resolve race condition in user login flow"

In your description, consider including:

  • A summary of the changes.
  • Links to any related issues (e.g., "Closes #123").
  • Instructions on how to test the changes (e.g., "Run npm test and check the login form with invalid credentials").
  • Visual evidence (e.g., screenshots or GIFs if you are changing the UI).

Respond to Feedback Gracefully

Code review is not a personal critique. It is a technical conversation intended to improve the product. When a reviewer asks a question or suggests a change, view it as an opportunity to learn or improve the code. If you disagree with a suggestion, explain your reasoning clearly and provide evidence. Do not take feedback defensively.

Use Draft Pull Requests

If you are still working on a feature but want to get early feedback or ensure your code passes automated tests, use GitHub's "Draft" PR feature. This signals to your team that the work is in progress and not ready for a final merge, preventing premature reviews.

Not read yet

The Reviewer's Perspective: How to Provide Quality Feedback

When you are on the other side of the screen as a reviewer, your goal is to ensure the code is correct, maintainable, and aligned with team standards. Being a good reviewer is just as important as being a good author.

Be Kind and Constructive

Use inclusive language. Instead of saying "You did this wrong," try saying "Could we consider doing this instead because it might be more performant?" Focus on the code, not the person. If you see a recurring issue, suggest a broader improvement rather than just pointing out the immediate error.

Verify Functionality

Do not just look at the code. If possible, pull the branch down locally and run it. Verify that the feature works as expected and that it doesn't break existing functionality. Automated tests are great, but manual verification of the user experience is often necessary.

Use Code Suggestions

GitHub allows you to suggest code changes directly in the review comments. This is a powerful feature because the author can click "Commit Suggestion" to apply your change instantly. It saves time and reduces back-and-forth communication for small syntax fixes or style improvements.

Warning: Avoid "LGTM" Without Review Simply writing "Looks Good To Me" (LGTM) without actually reading the code is a disservice to your team. It undermines the entire purpose of the review process. If you don't have time to review, it is better to say "I'll get to this later today" than to provide a hollow approval.

Not read yet

Managing Conflicts and History

As you work on your PR, the target branch (main) might continue to evolve. Other developers might merge their code, creating a situation where your branch is now "out of date" or contains conflicts.

Keeping Your Branch Up-to-Date

You should regularly pull the latest changes from the target branch into your feature branch. This ensures that you are developing against the most current version of the code and helps you identify conflicts early.

# While on your feature branch
git fetch origin
git merge origin/main

If there are conflicts, Git will pause the merge and ask you to resolve them. Open the affected files in your editor, look for the conflict markers (<<<<, ====, >>>>), and choose the correct code. Once resolved, stage the files and finish the merge.

Squashing Commits

Before merging, many teams prefer to "squash" their commits. If you have a long history of "fix typo," "adjust spacing," and "oops" commits, these don't provide much value to the project history. Squashing combines all your work into a single, clean commit.

# Interactive rebase to squash commits
git rebase -i HEAD~n  # where n is the number of commits to look back

In the interactive window, you can change the word pick to squash (or s) for the commits you want to merge into the previous one. This results in a clean, professional commit history for the main branch.

Not read yet

Comparison Table: Common PR States

State Meaning Action Needed
Open PR is active and under review. Reviewers provide feedback; Author addresses it.
Draft PR is a work-in-progress. No review required yet; useful for early feedback.
Changes Requested Reviewer identified issues. Author must address comments and push new commits.
Approved Reviewer is satisfied. Ready for merge once CI passes.
Closed PR was closed without merging. No further action; usually due to abandoned work.
Merged Changes are in the target branch. PR lifecycle complete.

Handling Complex Scenarios

What if my PR is too large?

If you realize your PR has become too large, the best course of action is to "split" it. You can create a new branch, cherry-pick the relevant commits, and open a separate PR. This might feel like extra work, but it will significantly increase the likelihood of your code being reviewed and merged quickly.

What if I need to change the base branch?

Sometimes you might accidentally open a PR against the wrong branch (e.g., main instead of develop). GitHub allows you to edit the base branch of an existing PR. Click the "Edit" button next to the PR title or use the command line to reset the base of your branch.

How to deal with CI/CD failures?

Most modern teams use Continuous Integration (CI). If your PR shows a red "X" next to your commit, it means your code failed a test or a linting check. Click the "Details" link to see the logs. Do not ask for a review until the CI tests are passing.

Not read yet

Best Practices Checklist for Pull Requests

To ensure your team maintains a high standard, consider adopting this checklist:

  • Automated Testing: Does the code pass all unit and integration tests?
  • Linting: Does the code follow the project’s style guide?
  • Documentation: Are new features documented in the code or README?
  • Clean History: Have you squashed unnecessary "fix" commits?
  • Scope: Does the PR only address the stated issue?
  • Reviewers: Have you tagged the appropriate people for review?
  • Testing Instructions: Have you provided clear steps on how to verify the work?

Common Pitfalls to Avoid

  1. Ignoring Reviewer Comments: If a reviewer asks a question, answer it. Ignoring comments is the fastest way to get your PR ignored.
  2. Merging Your Own PR: Even if you have the permissions, avoid merging your own code without at least one other set of eyes on it. It bypasses the safety mechanism of the PR process.
  3. Not Pulling Main: If you don't keep your branch updated, you will eventually face a massive merge conflict that is difficult to resolve.
  4. Writing Vague Commit Messages: "Fix" or "Update" tells future developers nothing about the history of the project.
  5. Taking Feedback Personally: Remember that the goal is to make the software better, not to judge your individual skills.

Not read yet

FAQ: Frequently Asked Questions

Q: How many people should review a PR? A: For most projects, one or two reviewers are sufficient. For critical infrastructure or security-sensitive code, you might require three or more.

Q: What if I don't know how to fix a comment? A: Ask for help! A PR is a great place to learn. You can reply to a comment saying, "I'm not sure how to implement this pattern, do you have any suggestions or resources?"

Q: Can I push more code after someone has already reviewed my PR? A: Yes, absolutely. In fact, you should. After you push new commits, the reviewers will be notified, and they can review only the new changes.

Q: Does a "Merge" button always mean a standard merge? A: Not necessarily. GitHub offers "Squash and merge" and "Rebase and merge" options. "Squash and merge" is very popular because it keeps the main branch history very clean.

Conclusion: Mastering the Collaborative Workflow

Pull Requests are more than just a technical step in a deployment pipeline; they are the social and intellectual glue that holds a development team together. By embracing the Pull Request workflow, you contribute to a culture of transparency, accountability, and continuous improvement.

When you open a well-structured Pull Request, you are showing respect for your teammates' time. When you provide thoughtful, constructive feedback on someone else's PR, you are helping to raise the quality bar of the entire organization. It is through these small, consistent interactions that robust, reliable software is built.

Key Takeaways

  • Communication is Key: A Pull Request is a conversation. Use the description to provide context and instructions for your reviewers.
  • Keep it Small: Smaller PRs are reviewed faster, have fewer bugs, and are easier to reason about than large, monolithic changes.
  • Respect the Process: Always use branches, follow the CI/CD feedback loop, and ensure your code is tested before requesting a review.
  • Feedback is Growth: Treat code reviews as a learning opportunity. Be open to suggestions and provide clear, professional responses to feedback.
  • Maintain Hygiene: Use tools like rebase and squash to keep your commit history clean and meaningful for those who will read it in the future.
  • Continuous Integration: Never ignore failing tests. Automated checks are your first line of defense against regressions.
  • Be a Good Citizen: When reviewing, aim to be helpful and kind. Your goal is to improve the codebase, not just to find faults.

By internalizing these practices, you will significantly improve your efficiency as a developer and become a more effective collaborator. Whether you are working on a small side project or a large enterprise system, these fundamentals remain the gold standard for high-quality software development.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.