A Pull Request (PR) is a feature used to propose changes from one branch or repository to another. Pull requests are commonly used on GitHub for code review, discussion, testing, and merging changes.
git pull. A pull request is a collaboration feature on
GitHub, while git pull is a Git command used to retrieve
and integrate changes from a remote repository.
A pull request is a request to review and potentially merge changes from one branch into another.
Feature Branch
↓
Pull Request
↓
Review
↓
Merge
↓
Target Branch
Pull requests provide a structured way to review and discuss code before it is merged.
| Pull Request | git pull |
|---|---|
| GitHub collaboration feature | Git command |
| Used to propose and review changes | Retrieves and integrates remote changes |
| Created on a Git hosting platform | Executed in a local Git repository |
The source branch contains the changes being proposed.
feature-login
↓
Pull Request
The source branch may exist in the same repository or, in a fork workflow, in a different repository.
The target branch is the branch into which the changes are proposed to be integrated.
feature-login
↓
PR
↓
main
The target branch is selected when creating the pull request.
A common workflow starts by creating a feature branch.
git switch main
git pull
git switch -c feature-login
The feature can then be developed independently from the main branch.
After creating a feature branch, modify the project files as needed.
git status
git add .
git commit -m "Add login feature"
The changes should be committed before pushing the branch.
Push the branch to the remote repository:
git push -u origin feature-login
After pushing, the branch can be used to create a pull request.
After pushing your branch, open the repository on GitHub and create a pull request from the source branch to the desired target branch.
feature-login
↓
Create Pull Request
↓
main
A pull request should have a clear title describing the proposed change.
Add user login functionality
A good title makes the purpose of the pull request easy to understand.
The description explains what the pull request changes and why the changes were made.
## What changed?
- Added login form
- Added validation
- Added session handling
## Testing
- Tested valid login
- Tested invalid password
Repositories can use reviewers to examine proposed changes. Reviewers can inspect the code and provide comments or request changes.
Developer
↓
Pull Request
↓
Reviewer
↓
Comments / Approval / Changes
Code review allows developers to examine the proposed changes before they are merged.
Reviewers may check:
Reviewers and contributors can discuss the proposed changes using comments.
Reviewer:
Could this validation be moved into
a separate function?
Developer:
Yes, I will refactor it.
A reviewer can request changes when the proposed code needs modification before it can be accepted according to the project's review process.
Pull Request
↓
Code Review
↓
Changes Requested
↓
Developer Updates Code
↓
Review Again
A pull request is normally updated automatically when new commits are pushed to its source branch.
git add .
git commit -m "Fix review comments"
git push
The new commit becomes part of the existing pull request.
Repositories can use automated checks to validate pull requests.
Examples include:
The exact checks depend on the repository configuration.
After the required review and checks are completed, an authorized person can merge the pull request according to the repository's settings and workflow.
Feature Branch
↓
Pull Request
↓
Review
↓
Checks
↓
Merge
↓
Target Branch
GitHub repositories can be configured with different methods for integrating pull requests.
Common approaches include:
Which method is available depends on repository settings and branch rules.
Pull requests can be associated with GitHub Issues to connect development work with a reported bug or requested feature.
Issue #25
↓
Feature Branch
↓
Pull Request
↓
Code Review
↓
Merge
This creates a connection between the problem and the code that addresses it.
GitHub supports keywords that can link a pull request to an issue and automatically close the issue when the pull request is merged.
Fixes #25
The exact result depends on the repository and the way the pull request is merged.
In an open-source workflow, contributors can create a fork, make changes in their fork, and then submit a pull request to the original repository.
Original Repository
↓
Fork
↓
Feature Branch
↓
Pull Request
↓
Original Repository
A draft pull request can be used when the work is still in progress and is not yet ready for final review or merging.
Work in Progress
↓
Draft Pull Request
↓
Continue Development
↓
Ready for Review
Labels can help organize pull requests.
Examples include:
The available labels depend on the repository.
Title:
Add student attendance report
Description:
## Changes
- Added monthly attendance report
- Added attendance percentage
- Added date filter
## Testing
- Tested monthly filter
- Tested student search
Related Issue:
Fixes #25
git switch main
git pull
git switch -c feature-report
# Make changes
git add .
git commit -m "Add attendance report"
git push -u origin feature-report
↓
Create Pull Request
↓
Code Review
↓
Automated Checks
↓
Fix Requested Changes
↓
Review Again
↓
Merge Pull Request
A pull request provides a structured way to propose, discuss, review, test, and potentially merge changes into another branch.
Feature Branch
↓
Push Changes
↓
Pull Request
↓
Review
↓
Automated Checks
↓
Changes if Needed
↓
Approval
↓
Merge
Pull requests are an important part of collaborative Git and GitHub workflows because they provide a place for code review and discussion before changes are integrated.
git pull command.Question: What is the main purpose of a Pull Request?