Working with Forks on Github
Just some quick info all in one place to help anyone who wants to know how to Fork a repo on Github.
The first step, clicking the “Fork” button, is the easy part. But once you’ve forked a repo and cloned it to your local workspace, you’ll still need to figure out how to work with the original project, especially if you intend to contribute back into it. Since I couldn’t find one place that had all this info, I decided I’d just write this stuff up (more for my own reference, but hopefully it’ll be useful to someone?)
Okay, so you’ve been doing some work in your Fork. Like a good Git user, you’ve been periodically pushing your changes up to your remote on Github. But what happens if the original repo has been updated?
I mean, we all know you should be pulling pretty frequently, in order to avoid any merge conflicts. Follow these steps to pull from the original repo.
Note: The first part of this is covered in Github’s help pages.
- Take a look at the current remote repos using the command: git remote -v
- Okay, unless you’ve already set it up, you probably will only see the pointers to your Github repo, which is probably called origin.
- Let’s add an upstream remote repo. To do, use the following command: git remote add upstream <original repo’s url> (use either the SSH or HTTPS url that you would use to clone a repo).
- Now, when you want to pull from the original repo’s master branch, just use the following command: git pull upstream master.
Okay, so like we said, you’ve been a good Git user: you’ve been committing frequently, pushing up to your Github regularly, and you’ve finished an awesome new feature on a new branch. Awesome! Now you want to contribute to the original repo. This part is surprisingly easy, even if the language is a bit confusing. What you need to do is make a Pull Request.
- Navigate to the Github page for your forked repo.
- Click the bright green New pull request button.
- If for some reason you can’t see any of the forks on this page (this happens if you get here by clicking New pull request on the original repo’s page, for example), just click the link that says compare across forks — this will toggle whether forks are shown.
- For base fork you want to choose the original repo.
- For base choose the name of the branch on the original repo into which you want your changes merged.
- For head fork choose your own fork. You are comparing your fork to the original repo. You are trying to pull your fork into the base, the original repo. (I know, this lingo can be a bit confusing).
- For compare select the branch you want to merge into the original repo.
- Click Create Pull Request. This will show all the commits you’re requesting the original repo to pull in.
- Enter a title and a description (I seriously recommend this!) and then click Create Pull Request one last time to send your pull request to the owner of the original repo.
And that’s it! Hopefully this is a helpful post — let me know if you have any questions, or corrections, or feedback, or just want to say hi!
Originally published at paloobi.tumblr.com.