The concept of a pull request is unique to GitHub — so don't feel nervous about not knowing what it is! "Pull requests" power the communities of developers who create and contribute to "open sourced" projects on GitHub.
Through this process, anyone can
- fork a repo from its original organization
- clone it to a local machine
- Make changes in a feature branch on their local system
- push their branch to their forked repo
...and now the critical step....
- Suggest that the original organization pull the changes that make up the feature branch back to the original repository.
Instead of the owner working on their codebase alone, anyone can contribute tests, documentation fixes, new features, layout, graphics, etc. It's an awesome feeling when you wake up and see that someone you've never met has made an improvement to your code that they'd like to contribute! How does this feature work?
- Explain what a pull request is
- Identify how to create a pull request from a fork to a repo
- Identify how to add commits to an existing pull request
A pull request is a request to the owner of another repo to take changes you
made in a branch on your fork of their repo and integrate it into theirs as
if you had done the work on theirs directly. It is a request for the owner
of a repository to accept your changes, that you made on your own copy of the
repo ("your fork"), and "pull" them into the owner's repository. Here is
a great example of a pull request on the Ruby
codebase.
CAREFUL
git
has a command calledpull
which means "integrate changes made in a remote place to this current branch." Oddly, in a "pull request" this isn't really what's happening. You're asking someone togit merge
your branch into theirs — a completely different command. It's needlessly confusing. We'll covermerge
later, but don't get confused bygit pull
and "pull request."
Let's go over a conceptual, hypothetical example. It's okay if this feels a bit confusing at first. You'll work through this countless times and eventually your brain and fingers will both grasp what's going on. Let's look at the following example:
- Let's pretend that the
learn-co-students
organization has a repo called awesome-lab, and we make a "fork" from this repo athttps://github.com/learn-co-students/awesome-lab
. - You would now have a copy of that repo on your GitHub account ("organization") i.e.
https://github.com/your-user-name/awesome-lab
. Technologists would say you "forked" theawesome-lab
repo from thelearn-co-students
organization to theyour-user-name
organization. - However, you still would not have a local copy of this repository on your computer.
- You would clone from your fork to your computer. There's no reason you couldn't clone from the original repo. However, most repo owners don't want random people on the internet (like you!) committing to their repo. What you're going to do is establish a "parallel" repo in your org and then tell the "source" repo "Hey, I added something awesome, I'm requesting that you pull it in."
- Make some changes on your local machine in a branch
- Push your code branch from your local system back to your fork
- Create a
pull request
that requests your improved code be "pulled" into the source repo. Observe the steps for initiating apull request
below:
Be sure to click New pull request on your fork instead of on the source repo. Otherwise, GitHub won't see the changes that you want to make.
Here you can choose the base fork, which will be their-user-name/awesome-lab
.
Then choose the head fork, which will be your-user-name/awesome-lab
Now click Create pull request, and you're all set!
What if another student now forks the repository
https://github.com/learn-co-students/awesome-lab
as https://github.com/their-user-name/awesome-lab
, then you make some changes and you
want to send a pull request to their fork https://github.com/their-user-name/awesome-lab
?
How do you do this?
Luckily, git
doesn't care whether one repository is the "source" or is
"another fork of the source." If GitHub magically vanished tomorrow, local copies on
hundreds of laptops 'round the world are just as good as the copy that GitHub had!
This is why git
is called a "Distributed Version Control System." So, to share a
pull request with another student follows the same process as forking some famous
project (like Ruby or jQuery).
Let's say you make a pull request from
https://github.com/your-user-name/awesome-lab
to
https://github.com/learn-co-students/awesome-lab
. Then you notice you made a
typo in your code. All you have to do is fix the typo, commit it and push up
the changes to your branch. As long as the pull request already exists, the
commits will be added automatically.
Pull requests are merely a tool that allows project owners and project editors to collaborate without granting too much direct access, or potentially stepping on each others' toes. This action can be performed even on a repo you are a collaborator on, but may not have write access to — but we won't get into that just yet. You'll continue to learn more about collaboration and how git enables you to track and edit projects to your heart's content!
View GitHub Pull Request Basics on Learn.co and start learning to code for free.