← Back to Git Course | Chapter 7: Collaboration | Lesson 1 of 6

Git Pull Requests

A pull request is like raising your hand to say 'I finished my part, please check it before we add it to the main project'. Friends can look and comment first.
Syntax
bash
git push -u origin branch_name
# open a pull request on the hosting platform

What is a Pull Request?

A pull request bundles up the commits on a feature branch and proposes merging them into another branch, giving reviewers a dedicated place to leave line-by-line comments, request changes, and approve before anything actually merges. It's a review gate layered on top of Git itself — the platform (GitHub, GitLab, etc.) tracks it, not Git.

Example: What is a Pull Request?

bash
git push -u origin feature-login
# then open a pull request on the hosting platform

Pushing Local Commits to a Pull Request

Because a pull request just points at a branch rather than a fixed set of commits, pushing new commits to that branch updates the PR automatically — reviewers see the new changes appear without you needing to open a second request.

Example: Pushing Local Commits to a Pull Request

bash
git commit -m "Address review comments"
git push

Fetching and Testing a Pull Request Locally

Checking out someone else's PR locally — via git fetch origin pull/ID/head:branch-name on GitHub, or a similar remote ref on other platforms — lets you actually run their code and tests on your machine before approving, which catches problems a diff view alone can miss.

Example: Fetching and Testing a Pull Request Locally

bash
git fetch origin pull/42/head:pr-42
git checkout pr-42

Merging a Pull Request

Once a PR has the required approvals and passes any automated checks, merging it folds its commits into the target branch — most platforms offer a choice between a regular merge commit, a squash merge, or a rebase, each leaving a different shape of history behind.

Example: Merging a Pull Request

bash
git checkout main
git merge --no-ff feature-login

Deleting Merged Branches

A merged feature branch has done its job and just adds clutter if left around — deleting it both locally (git branch -d) and on the remote (git push origin --delete <branch>) keeps the branch list meaningful and stops people from accidentally building on stale work.

Example: Deleting Merged Branches

bash
git branch -d feature-login
git push origin --delete feature-login
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Opening a pull request from main of your fork, so later unrelated commits get added to it.
  2. Creating a new pull request to fix review comments, when pushing more commits to the same branch updates the existing one.
  3. Making the pull request too large, so reviewers cannot follow it.
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.