Git Pull Requests

A pull request is a request to merge changes from one branch or fork into another, built around discussion and review before the merge happens.

What a Pull Request Actually Is

It's worth being precise here: a pull request, often shortened to PR, is not a Git feature at all. It's a feature provided by hosting platforms like GitHub, GitLab, and Bitbucket, layered on top of ordinary Git branches and commits. When you open a PR, you are asking the platform to compare two branches (or a fork branch against the original repository) and present that comparison as a reviewable, discussable unit of work before it gets merged.

Under the hood, a pull request is really just a diff between a source branch and a target branch, paired with a comment thread, a review workflow, and often automated checks like tests or linters. The actual merge, when it eventually happens, is performed using ordinary Git operations, most commonly a merge commit, a squash merge, or a rebase, depending on the project's conventions.

Forks vs Branches

There are two common shapes a pull request workflow can take, and which one applies depends on whether you have write access to the original repository. If you're a core contributor with push access, you typically create a new branch directly on the shared repository, push it, and open a PR from that branch into main. If you don't have write access, for example when contributing to an open-source project you don't maintain, you first fork the repository, creating your own copy under your account, make your branch and commits there, and then open a PR from your fork back into the original project.

  • Branch workflow: create a branch on the shared repo, push it, open a PR into main
  • Fork workflow: fork the repo to your account, branch and commit there, open a PR from your fork into the upstream repo
  • Both workflows produce the same kind of PR from the reviewer's perspective, just with a different source location

A Typical Branch-Based PR Flow

Creating a branch and opening a PR

$ git checkout -b fix/login-timeout
Switched to a new branch 'fix/login-timeout'

$ git add src/auth/session.js
$ git commit -m "Increase login session timeout to 30 minutes"

$ git push -u origin fix/login-timeout
...
remote: Create a pull request for 'fix/login-timeout' on GitHub by visiting:
remote:      https://github.com/acme/project/pull/new/fix/login-timeout
To github.com:acme/project.git
 * [new branch]      fix/login-timeout -> fix/login-timeout

Notice that git push itself has no concept of pull requests; it simply uploads the branch. GitHub, watching for new branches, prints a helpful shortcut URL in the terminal output that takes you straight to the 'open a pull request' form on the website.

The Review Cycle

Once a PR is open, reviewers can leave comments on specific lines, request changes, approve, or in some setups block a merge until CI checks pass. If a reviewer asks for changes, you simply commit more work on the same branch and push again; the existing PR updates automatically to show the new commits, there is no need to open a new PR for follow-up fixes.

Pushing follow-up changes after review feedback

$ git add src/auth/session.js
$ git commit -m "Address review: extract timeout constant"
$ git push
Enumerating objects: 5, done.
...
To github.com:acme/project.git
   9a01cde..1120fab  fix/login-timeout -> fix/login-timeout
Note: Many teams also allow reviewers to push directly to your PR branch, particularly for small fixups, if the branch was created with the 'allow edits from maintainers' option enabled on GitHub.

Merge Strategies

StrategyHistory resultBest for
Merge commitPreserves every commit plus a merge commit tying branches togetherFeature branches where individual commit history matters
Squash and mergeAll PR commits collapsed into a single commit on the target branchKeeping main's history clean and readable
Rebase and mergePR commits replayed individually onto the target, no merge commitLinear history without losing granular commits
Note: Whichever strategy a repository uses, always pull the target branch after a PR merges before starting new work from it. Your local main can otherwise fall behind quickly on an active project.

Good PR Hygiene

Small, focused pull requests get reviewed faster and more carefully than sprawling ones. A PR that changes one thing with a clear description is far easier for a reviewer to reason about than a five-thousand-line diff touching a dozen unrelated files. Writing a clear PR description, referencing any related issue, and keeping commits logically organized all make the review process smoother for everyone involved.

Exercise: Git Pull Requests

What is a "pull request" (PR)?