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

Git Pull Requests

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
🔒

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.