Forking with Git
Overview
Let’s look at how one can fork a github repository and stay up-to-date with upstream changes. Finally we’ll look at ways of committing changes back to the upstream.
Fork it
Forking a github repository is a simple as clicking on the fork image-link. This will create a new fork of the repo that you “own”.
Git it
Once you made a fork you can git clone it like usual. For example:
git clone git@github.com:mateu/mojomojo.git
This puts a copy (clone) of my fork of the mojomojo repo onto my local machine.
Track the source of the Fork
In order to track the source repository of the fork we use the git remote add command as such:
git remote add upstream git@github.com:marcusramberg/mojomojo.git git fetch upstream
Now we are tracking the original repo we forked from under the name “upstream”.
Merge updates from the original repo (upstream) master branch
To get any changes to the upstream master since last fetching it:
get fetch upstream master get merge upstream/master
An alternative way is the one step:
get pull upstream master
The two step way is recommended on github for easier management of merge conflicts.
Apply Fork Changes to Upstream
If you have commit access to the upstream you can do:
git push upstream master
In effect we’re treating a fork somewhat like a branch here. If you don’t have commit access the your fork changes can be applied to the upstream by making a pull request from your github page.
Delete Fork
If you’re done with your fork (you can always refork) and would like to delete it then use the “Delete This Repository” link at the bottom of your github Admin page for the repo.
Showing changes from previous revision. Removed | Added
