Github Setup

There is a project I want to work with on github, but I want my own repository where I can work on my own stuff, but still fetch changes from the main project. I don't want to commit my changes to the main project, but I want to allow them to pull some of my commits. I would have thought that was a common requirement, but it turns out to be mildly complex to achieve.

First clone the main project on Github using the web interface. In this example the main project is tipam/pi3d, and my clone is rurwin/pi3d.

Next install git-core on your local PC and clone the main project there too.

pi@raspberrypi ~ $ git clone
Cloning into 'pi3d'...
remote: Counting objects: 4067, done.
remote: Compressing objects: 100% (1556/1556), done.
remote: Total 4067 (delta 2773), reused 3794 (delta 2505)
Receiving objects: 100% (4067/4067), 71.48 MiB | 33 KiB/s, done.
Resolving deltas: 100% (2773/2773), done.
Checking out files: 100% (358/358), done.

Now we create a remote called publish to allow us to push our commits up to our github repository.

pi@raspberrypi ~ $ cd pi3d
pi@raspberrypi ~/pi3d $ nano .git/remotes/publish
Push: +master:master
Push: +integration:integration

There's one of those "Push" lines for each branch in the main project (that we are interested in). The "+" tells it to always overwrite, so no matter what we do to our local repository it will be mirrored on our github repository.

As yet we have only created the master local branch, so we checkout the other branch (from the main repository) and create it locally:

pi@raspberrypi ~/pi3d $ git checkout -b integration origin/integration
Branch integration set up to track remote branch integration from origin.
Switched to a new branch 'integration'

We now have access to both branches on the main project. Let's test that:

pi@raspberrypi ~/pi3d $ git checkout master
Switched to branch 'master'
pi@raspberrypi ~/pi3d $ ls      models             screenshots   fonts        
ChangeLog.txt            textures  images               readme.html  include    
pi@raspberrypi ~/pi3d $ git checkout integration
Switched to branch 'integration'
pi@raspberrypi ~/pi3d $ ls
ChangeLog.txt  echomesh  pi3d         screenshots        fonts     LICENSE      readme.html  shaders          textures
demos          images    models

Finally we publish the contents of our local repository to our github repository:

pi@raspberrypi ~/pi3d $ git push publish
Username for '': rurwin
Password for '': 
Counting objects: 141, done.
Compressing objects: 100% (72/72), done.
Writing objects: 100% (110/110), 5.96 MiB | 118 KiB/s, done.
Total 110 (delta 47), reused 100 (delta 38)
   a49ba04..c2127ff  integration -> integration
 + 568f302...1061894 master -> master (forced update)

And just to prove it, here's my github network with all the commits in it and none anywhere else, proving my github repository is a full and correct copy of the latest main project.


So now we can keep our local repository up-to-date with the main project repository but we can publish our commits to github where we can raise a pull request to the main project.

My thanks to Jeff King for the huge help in constructing this. Any mistakes or misinterpretations are all mine.

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License