What is a Pull Request?
Most software projects are developed through collaboration—whether between a software team building a product or among individual developers creating an open-source project.
Developers need a way to experiment with and isolate changes, such as new features, separate from the project. This makes it easy to track, discuss, and reverse changes as needed without altering the main project.
In essence, a project’s maintainer can check the isolated code and make sure it’s up to snuff before merging it into the main (upstream) repository.
When the project contributor finishes working on their local code, they can then submit a pull request.
What is a pull request?
A pull request tells the project maintainer that you’ve finished working on your local code in your external repository and would like them to review it before merging it into the project’s upstream repository.
Many people using a distributed version control system (DVCS) to work on projects prefer pull requests as their means of submitting project contributions. They’re especially popular on open-source platforms like GitHub because it allows for easy review and implementation of new code.
How do pull requests work?
If you’re working on an open-source project in a platform such as GitHub, you create a clone of the main source code repository for your local development environment. That way, you can experiment freely with new code without harming the main project.
As you make changes, you can commit them to your local repository to create a revision history. That history makes it easy for the project maintainer to understand what your code changes do. It also helps you remember what new features you’ve developed.
When you fill a pull request, you’re asking the project’s maintainer to move one of your repository’s branches into their own. They can then look over the code, make edits, suggest changes, and more.
In many cases, the maintainer will send you back the code with suggestions for improvements to meet the project’s standards.
Otherwise, they’ll approve the code and merge it into the upstream repository.
Creating a pull request in GitHub
First, find the project you want to work on and navigate to the page with its main code repository.
From there, you’ll fork the repository, meaning you’ll create a copy of it on your GitHub account. Then, you’ll clone that fork onto your local machine and create a local branch to make changes.
Finally, you can begin working on your own ideas with the code. Every time you make a change, commit it to your local branch with a descriptive, informative message about the nature of that change. Remember: You can’t transfer any changes back if you haven’t committed them.
When you’re done, push your local branch back to your GitHub fork, head back to the upstream repository’s page and click on the “Pull requests” tab.
Here is where you’ll submit your pull request. You’ll be asked to write up a brief description of the changes you made and what you intend them to do.
Accepting a pull request
Now, let’s look at the project maintainer’s side of things.
Once the developer submits the pull request, it’s time for the project maintainer to look over and possibly merge the code into the main repository.
The approval process may differ in specifics depending on the type of project. That said, the general process is pretty simple:
- First, look over the changes and see what the contributor added to the project.
- Study the code and prepare feedback for the person who submitted the code—you may have to ask for a resubmission.
- Test the new code.
- Ask the contributor to fix any problems, if necessary, and resubmit.
- Look over the code and test one final time, then pull the code into the main repository.
The code will now be available for anyone else working on the project to look at.
Can you automate pull requests?
Managing and approving pull requests occupies your team’s time with tedious manual work. Fortunately, you can automate much of the process by writing a few rules that take action on pull requests automatically.
In Mergify, you can simply set your rules for pull requests and prioritize them based on urgency; our bot can automatically merge them into your main repository.
Mergify makes it easy to onboard new developers and get them up to speed on how to contribute to your repository. That way, they can contribute their talents and creativity to the project in less time.
Mergify is free for open-source projects, so sign up today. If your project isn’t open-source, you can still try us free for 14 days!