Pull Requests (PRs)
In Git and platforms like GitHub, GitLab, or Bitbucket, a Pull Request (PR)—also called a Merge Request on some platforms—is a way to submit code changes so other team members can review, discuss, and merge them into the main codebase.
Learn how a Pull Request works, which Git commands you need, and the best practices for submitting changes to a shared project.
How a Pull Request Works
1. Create a Feature Branch
Create a separate branch so you can work on a feature without directly changing the main branch.
git checkout -b feature/your-feature-name
2. Push Your Branch to the Remote
After committing your changes, push your branch to GitHub or your chosen hosting platform.
git push -u origin feature/your-feature-name
3. Open the Pull Request
- Open your repository on GitHub.
- Navigate to the Pull Requests section.
- Click New pull request.
-
Select your feature branch as the source branch
and
mainordevas the target branch. - Add a title and description, then create the PR.
4. Review the Code
Team members inspect your changes, leave comments, discuss implementation details, and request changes when necessary.
5. Merge the Pull Request
Once the required reviews and checks are complete, an authorized team member can merge the changes into the target branch.
Essential Git Commands for PRs
1. Create and Switch to a Branch
git checkout -b feature/your-feature-name
2. Stage and Commit Your Changes
git add .
git commit -m "Add description of your changes"
Stage the files you intend to include and use a descriptive commit message.
3. Push Your Branch
git push origin feature/your-feature-name
Uploads your branch to the remote repository. Some GitHub workflows may display a URL in the terminal that you can use to open a Pull Request.
Best Practices for Pull Requests
1. Keep Pull Requests Small
Smaller PRs are easier to review, understand, test, and maintain.
2. Write Clear Descriptions
Explain what you changed, why you made the change, and how reviewers can test it.
3. Synchronize with the Target Branch
Before opening a PR, check whether your target branch has new commits. If necessary, integrate them into your feature branch.
git fetch origin
git switch feature/your-feature-name
git merge origin/main
Resolve any conflicts and push the updated feature branch before requesting review.
main with your actual target
branch if your project uses another branch, such as
dev.
Quick Reference
| Command | Purpose |
|---|---|
git checkout -b feature/name |
Create and switch to a feature branch |
git add . |
Stage changes in the current directory |
git commit -m "message" |
Create a commit |
git push -u origin feature/name |
Push a branch and configure upstream tracking |
git fetch origin |
Download remote updates without integrating them |
git merge origin/main |
Integrate the fetched target branch into your current branch |