Github Pull Requests
Problem Statement
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. How does this feature work? 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!
Objectives
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
Explain What a Pull Requests Is
NOTE The term “pull requests” comes from the distributed nature of how many open source projects organize themselves. Instead of pushing your changes into a central repository, you are publishing your changes separately and asking the maintainer to pull in your changes. The maintainer then can look over the changes and do said pull. This is not the same as by
git pull
, which will integrate changes made in a remote repo to the your local version of the branch.
Identify How to Create a Pull Request from a Fork to a Repo
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:
Step 1
Step 2
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).
Identify How to Add Commits to an Existing Pull Request
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.
Conclusion
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!
Last updated