Pull Request
In short
A pull request is a proposal to merge changes from one branch into another, giving teammates a place to review, discuss, and test the code before it is merged.
What is a pull request?
A pull request, often shortened to PR, is how developers ask for their changes to be added to a shared codebase. You push a branch with your commits to a hosting platform and open a pull request asking to merge it into a target branch, usually main. The pull request shows exactly what changed, line by line, alongside a description of why.
Pull requests are the center of code review. Teammates can leave comments on specific lines, request changes, or approve the work. Most teams also connect pull requests to CI/CD pipelines, so automated tests and checks run on every update and must pass before the pull request can be merged.
Pull requests are a feature of hosting platforms such as GitHub, Bitbucket, and Azure DevOps, not of Git itself, and GitLab offers the same thing under the name merge request. The name comes from the idea that you are asking the project's maintainers to pull your changes into their branch.
Opening a pull request is like submitting an article draft to an editor. The editor reads it, suggests edits, and publishes it only once it meets the publication's standards. Small, focused pull requests are much easier and faster to review than large ones that change many things at once.
At a glance
Key takeaways
- A pull request proposes merging one branch into another.
- It is the main place for code review, discussion, and approval.
- Automated tests usually run on every pull request before it is merged.
- GitLab calls the same feature a merge request.
- Small, focused pull requests get reviewed faster and more thoroughly.
Example
# Create a branch and commit your work
git switch -c fix/login-redirect
git commit -am "Fix login redirect loop"
# Push the branch to the remote repository
git push -u origin fix/login-redirect
# Then open the pull request in your hosting platform's web UI,
# or from the terminal with its CLI tool (GitHub's is shown here)
gh pr create --base main --title "Fix login redirect loop"Readers ask
What is the difference between a pull request and a merge request?
They are the same concept with different names. GitHub, Bitbucket, and Azure DevOps call it a pull request, while GitLab calls it a merge request.
Is a pull request part of Git?
Not really. Git has a git request-pull command that generates a summary of changes to send by email, but the interactive pull requests with reviews and comments that most developers use are features of hosting platforms built on top of Git.
How big should a pull request be?
As small as practical, ideally focused on a single change. Many teams aim for pull requests of a few hundred lines or fewer, because smaller changes are reviewed more carefully and merged sooner.
See also
- GitVersion Control, p. 10Git is a free, open-source distributed version control system that tracks changes to files over time, so developers can collaborate and undo mistakes.
- BranchVersion Control, p. 2A branch in Git is an independent line of development that lets you work on a feature or fix in isolation, without affecting the main code until you merge it.
- MergeVersion Control, p. 29A merge in Git combines the changes from one branch into another, joining separate lines of development back together into a single, shared history.
- CommitVersion Control, p. 5A commit is a saved snapshot of a project's files in Git, recorded with a unique ID, an author, a timestamp, and a message describing what changed.
- CI/CDDevOps & Cloud, p. 9CI/CD is a set of automated practices that build, test, and release code changes frequently, so software can be delivered to users quickly and safely.
- DevOpsDevOps & Cloud, p. 14DevOps is a set of practices and a culture that brings software development and IT operations together to deliver software faster and more reliably.
- GitHubVersion Control, p. 25GitHub is a platform for hosting Git repositories and working on code together, with pull requests, code review, issues and the largest open-source community.
Spotted a mistake or something missing on this page?Suggest an edit