Fun with Learning Technology
LearnCoursesQuestionsTracksToolsNewsExplorePractice
Fun with Learning Technology

A new problem, explained clearly, every day.

Subscribe
Learn
  • Lessons
  • Topics
  • News
  • Tools
  • Courses
  • Career tracks
  • Everything
Site
  • About
  • Contact
  • Support
  • Privacy
  • Terms
Get the daily one

One email per new problem. No spam.

Request a tutorial

Requests shape what gets made next.

© 2026 Fun with Learning TechnologyRSS
Home›Courses›Git & GitHub›Pull Requests and Code Review

GitHub

Pull Requests and Code Review

Pull Requests are a collaborative mechanism for proposing changes to a repository by allowing team members to discuss and evaluate code before it is merged into the main branch. They serve as the primary quality gate in modern software development, ensuring that new features or bug fixes meet team standards and do not introduce regressions. You use them whenever you have completed a task in a feature branch and are ready to integrate your contribution into the shared codebase.

Understanding the Pull Request Workflow

A Pull Request acts as a formal communication channel between your local development environment and the remote repository. When you push a feature branch to GitHub, the Pull Request interface captures the delta between your branch and the target branch. This is vital because it creates a persistent, searchable, and structured environment for asynchronous collaboration. Instead of emailing code snippets, stakeholders can review the entire context of your work, including documentation and test cases. The workflow ensures that no code is merged without passing through a predefined review process, which minimizes the risk of breaking production-ready code. By utilizing Pull Requests, the team shifts from a 'cowboy coding' mindset to a peer-reviewed, accountable development culture. You gain peace of mind because your work is vetted by peers before it impacts the rest of the project ecosystem. This process is the cornerstone of professional software engineering practices.

# 1. Create a branch for a new task
git checkout -b feature/user-authentication

# 2. Add changes, commit, and push to remote
git add . 
git commit -m "Implement OAuth flow"
git push origin feature/user-authentication

The Code Review Process

Code review is the analytical phase where team members examine the changes submitted in a Pull Request. This process is not merely about finding bugs; it is about knowledge sharing, enforcing architectural consistency, and ensuring that the code is maintainable for future contributors. When a reviewer inspects your code, they are looking for logical errors, potential edge cases, and adherence to team-specific style conventions. Effective code review requires reviewers to be both critical and constructive, asking questions rather than issuing commands. By providing feedback through the GitHub interface, reviewers can link comments to specific lines of code, creating a clear audit trail of why certain modifications were requested. This iterative cycle of feedback and revision refines the code quality and helps junior developers grow by learning from seasoned experts. Ultimately, code review creates a collective sense of ownership over the repository, ensuring that every merge maintains high quality standards.

# Locally, if you need to fix a review comment:
# Modify files based on feedback
git add . 
git commit -m "Address review feedback"

# Push updates to the same branch; PR updates automatically
git push origin feature/user-authentication

Handling Review Conflicts and Syncing

As you develop on a feature branch, the target branch (such as main) often evolves independently. This creates a divergence where your branch may become stale, leading to conflicts or outdated logic. To keep your work relevant, you must periodically sync your local branch with the remote target. When you 'rebase' your branch onto the current target, you essentially re-apply your commits on top of the latest version of the repository. This is critical for preventing 'merge hell' later on. It also ensures that your automated tests are running against the most current version of the project dependencies. If your local history conflicts with the target branch, Git pauses the process to let you resolve the differences manually. Mastering this synchronization ensures that your Pull Request is always clean, testable, and ready to be integrated without disrupting other team members who are simultaneously contributing to the project.

# Fetch the latest history from the remote
git fetch origin

# Rebase your current branch on top of main
git rebase origin/main

# If conflicts arise, edit files then run:
git add . && git rebase --continue

Managing Merge Strategies

Once a Pull Request receives approval, it must be merged into the target branch. GitHub offers several strategies, such as 'Merge Commit', 'Squash and Merge', and 'Rebase and Merge'. Each has unique implications for the commit history. A 'Merge Commit' keeps all individual commits, which is helpful for seeing the chronological evolution of a feature, though it can create a cluttered history. 'Squash and Merge' condenses all your work into a single, clean commit on the target branch, which is often preferred for maintaining a tidy, linear project history. 'Rebase and Merge' maintains the commits but applies them linearly. Choosing the right strategy depends on your team's workflow and how much detail you want to preserve in the logs. Understanding these strategies allows you to control the repository's history, making it easier to debug issues or perform reverts if a regression is introduced later.

# If you must merge locally before pushing to target
git checkout main
git pull origin main
git merge --no-ff feature/user-authentication
git push origin main

Automation and CI/CD Integration

Modern Pull Requests are almost always integrated with Continuous Integration (CI) systems. When you open a Pull Request, the CI platform automatically triggers a suite of tests, linters, and security checks on your branch. This is an essential safety net; it prevents broken code from being merged before a human even lays eyes on it. If the build fails, the Pull Request UI displays the error status, signaling to the developer that adjustments are needed. This feedback loop is incredibly fast and reduces the cognitive load on human reviewers, as they can focus on logic and design rather than syntax errors or failing tests. By integrating these automated checks, you enforce a high quality bar for every single contribution. The combination of automated testing and human review creates a robust, secure pipeline that protects the repository from accidental corruption while maintaining high development velocity.

# Typical CI build script (e.g., .github/workflows/test.yml)
name: Test Suite
on: [pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: npm install && npm test

Key points

  • A Pull Request is the primary vehicle for proposing code changes in a shared repository.
  • Pull Requests enable asynchronous peer reviews, which improve code quality and knowledge sharing.
  • The code review process acts as a final barrier to prevent logical errors from reaching the production branch.
  • Keeping your feature branch synced with the main branch prevents future integration conflicts.
  • Rebasing allows you to integrate updates from the target branch while maintaining a clean project history.
  • Different merge strategies like squashing offer various levels of detail in the repository commit logs.
  • Automated CI integration provides immediate feedback on your code before a human reviewer begins their work.
  • Effective communication during the review process is just as important as the code itself.

Common mistakes

  • Mistake: Opening massive, monolithic pull requests. Why it's wrong: They are difficult to review thoroughly, lead to reviewer fatigue, and increase the likelihood of bugs. Fix: Break changes into smaller, logical, and incremental PRs.
  • Mistake: Ignoring the PR description or leaving it blank. Why it's wrong: Reviewers lack context on the 'why' behind the changes, making it harder to verify the business logic. Fix: Use a template to explain the motivation, testing steps, and relevant issue links.
  • Mistake: Arguing over subjective stylistic preferences in comments. Why it's wrong: It creates friction and slows down development. Fix: Use automated linting tools to enforce style, leaving comments only for architectural or functional concerns.
  • Mistake: Failing to pull the latest changes from the main branch before submitting. Why it's wrong: It causes unnecessary merge conflicts and delays the CI/CD pipeline. Fix: Regularly sync your feature branch with the target branch throughout the development process.
  • Mistake: Leaving unresolved 'conversation' threads. Why it's wrong: It obscures important decisions or pending work that needs follow-up. Fix: Use the 'resolve' button only after a clear resolution is agreed upon by both the reviewer and the author.

Interview questions

What is the basic purpose of a Pull Request in a GitHub workflow?

A Pull Request is a fundamental feature of GitHub that provides a dedicated space to discuss, review, and manage changes to a repository. Its primary purpose is to allow developers to propose changes from their feature branch into a base branch, such as main or develop. By opening a Pull Request, you create a transparent audit trail of the work being done. It facilitates collaboration because it allows team members to view diffs, comment on specific lines of code, and ensure that the proposed changes align with the project's requirements before they are actually merged.

What steps should a developer take before opening a Pull Request to ensure a smooth review process?

Before opening a Pull Request, a developer should always perform a final sync with the main branch. This involves pulling the latest changes from the remote main branch into their local feature branch to resolve any potential merge conflicts early. Additionally, the developer should review their own code for readability, remove any unnecessary debug statements or comments, and ensure that all commit messages are descriptive and follow the project's standards. Testing the code locally to verify it compiles and passes existing test suites is essential to show respect for the reviewer's time.

Compare the 'Merge Pull Request' strategy with the 'Squash and Merge' strategy. When would you use each?

A standard 'Merge Pull Request' preserves the entire history of commits from the feature branch, which is useful when you need a granular view of the development process for auditing. In contrast, 'Squash and Merge' combines all individual commits from a feature branch into a single commit on the base branch. I prefer 'Squash and Merge' for feature branches because it keeps the main project history clean, linear, and easy to navigate, avoiding the noise of 'fix typo' or 'wip' commits that often accumulate during development.

How should a developer handle feedback received during a code review on GitHub?

When a reviewer leaves feedback on a Pull Request, the developer should approach the comments with an open mindset. If the feedback is a suggestion to improve code quality or adherence to standards, the developer should implement the changes by pushing new commits to the same branch; these will automatically appear in the Pull Request. If the developer disagrees with a comment, they should reply in the thread with a clear technical justification or request a sync-up to discuss it. The goal is to reach a consensus, resolve the conversation threads, and ensure the code is production-ready.

What is the importance of a 'Draft' Pull Request, and how does it change the collaboration flow?

A Draft Pull Request is a critical tool for signaling that work is still in progress and not yet ready for a formal final review. By marking a PR as a draft, a developer prevents team members from accidentally merging the code before it is complete. It allows for 'early and often' feedback, enabling developers to share their architectural approach or progress with the team without triggering notifications for a full code review. This shifts the workflow toward iterative collaboration rather than waiting until the very end of a task to share results, which reduces the risk of major rework later.

Explain the role of GitHub Protected Branches and how they influence the Pull Request lifecycle.

GitHub Protected Branches are a security and quality control mechanism that restricts how changes can be merged into critical branches like main. When a branch is protected, you can enforce requirements such as 'Require pull request reviews before merging' or 'Require status checks to pass.' This forces a strict Pull Request lifecycle: code cannot bypass the review process. Even project administrators are prevented from force-pushing or deleting the branch. This is vital in professional environments because it guarantees that no code reaches production without passing CI/CD automated tests and peer oversight, significantly reducing the probability of regressions or insecure code deployment.

All Git & GitHub interview questions →

Check yourself

1. When a reviewer asks for changes, what is the best practice for updating your PR?

  • A.Delete the branch and open a completely new PR.
  • B.Push new commits to the same branch, which updates the existing PR.
  • C.Close the PR and ask the reviewer to manually edit your code.
  • D.Force push changes to the main branch to overwrite the previous history.
Show answer

B. Push new commits to the same branch, which updates the existing PR.
Pushing new commits to the existing branch is the correct way to iterate on a PR. Deleting the branch wastes the PR's history; closing it is unnecessary; force pushing to main is destructive and dangerous.

2. What is the primary benefit of keeping a pull request focused on a single task?

  • A.It hides mistakes by grouping them with correct code.
  • B.It forces the reviewer to focus only on stylistic issues.
  • C.It improves code quality by making the logic easier to audit and test.
  • D.It allows you to bypass the need for automated tests.
Show answer

C. It improves code quality by making the logic easier to audit and test.
Smaller PRs are easier to audit for logic errors. Option 1 is unethical, option 2 is not the goal of a review, and option 4 is never a valid practice.

3. If your PR has merge conflicts with the target branch, what is the recommended workflow to resolve them?

  • A.Merge the target branch into your feature branch and resolve conflicts locally.
  • B.Wait for the project maintainer to manually fix your conflicts.
  • C.Ignore the conflicts and hope the platform resolves them automatically.
  • D.Delete the files that are causing the merge conflicts.
Show answer

A. Merge the target branch into your feature branch and resolve conflicts locally.
You must pull the latest changes into your branch to resolve conflicts, ensuring your code works with the current state. Maintainers should not fix your conflicts, conflicts aren't auto-fixed, and deleting files breaks functionality.

4. Why is it important to provide a detailed description in your pull request?

  • A.To increase the character count for search engine indexing.
  • B.To explain the context, the rationale, and how to verify the changes.
  • C.To prevent other developers from understanding your code.
  • D.Because it is required to automatically merge the code without reviews.
Show answer

B. To explain the context, the rationale, and how to verify the changes.
Documentation helps reviewers understand intent, which is vital for effective code reviews. Other options are incorrect as they either hinder collaboration or provide false justifications.

5. What should you do if you disagree with a reviewer's feedback?

  • A.Ignore the feedback and merge the PR immediately.
  • B.Report the reviewer to the repository owner.
  • C.Start a respectful, objective discussion to explain your reasoning or clarify the approach.
  • D.Immediately accept the feedback even if you know it introduces a bug.
Show answer

C. Start a respectful, objective discussion to explain your reasoning or clarify the approach.
Code review is a collaborative process; discussion is expected when perspectives differ. Ignoring feedback or mindlessly accepting it is poor practice, and reporting a reviewer for feedback is unprofessional.

Take the full Git & GitHub quiz →

← PreviousForce Push — When and Why (carefully)Next →GitHub Actions — CI/CD Basics

Git & GitHub

20 lessons, free to read.

All lessons →

Track your progress

Sign in to mark lessons done, score quizzes and keep notes.

Open in the app