A pull request is a way of contributing to a Git project as a 3rd party. If you’ve found a bug or a way to improve something in an open-source project, you can use this to submit (commit) your changes to be reviewed by the moderators of that repo. The moderators have the ability to accept your changes and add them to their project, reject them, or alter and then accept them.
If you’re not familiar with Git or GitHub, we’ve got you covered with this Git & GitHub tutorial.
You’ve probably seen by now that GitHub repos can have multiple contributors, and you’re probably wondering how is that possible. I mean, if only one person owns the repo, how are these other people writing to it? Surely the answer is not manually giving access to every contributor to the repo, that would be madness. The answer is through Pull Requests.
How Pull Requests Work
Pull requests are a way to create commits to Git projects that don’t belong to you. As mentioned above, the reasons for doing this is to fix bugs or improve components.
You submit a pull request through GitHub’s website after you’ve cloned the repo locally and committed the changes to your own local version of the repo.
The commits from the pull request can be reviewed by everyone, as each pull request is public.
How to Create a Pull Request
Fork the Repo
Forking simply means copying a repository from one account to another. When we fork a repo, we copy the repo from the author to one of our own GitHub accounts. This allows us to clone it locally and create new commits.
To fork a repo, go to its page and click the button at the top right-hand corner called Fork.
Clone the Repo Locally
Navigate to where you want to place the code and clone the repo:
cd ~/Code git clone [email protected]:codepicky/some-repo.git
Create a New Branch for the New Changes
Let’s create a new branch and create a new branch and check it out:
git checkout -b my-bug-fix
That will create the my-bug-fix branch and switch branches to it.
Commit Your Changes
Edit the files as you please, then simply stage and commit them:
git add . git commit -m "Switched the clock's spinning direction."
Create the Pull Request
Go to the repo’s URL, click the Pull requests tab, then click New pull request.
GitHub will automatically see that you’ve made some changes to a repo called the same as the repo that you want to create a pull request for and will pre-fill the form with the required values. You just have to click Create pull request and provide a comment for the repo authors to be able to understand the value of your changes.