Automatically push commits from your repo to GitHub

If you have your git repositories on your own server, but want to mirror them on github, then this might be relevant for you.

Assume that you push your work to machine myhost via ssh. You want to mirror myrepo to github.

1. Generate ssh key and upload it to github

If the user you use to access your repos already has ssh key generated, skip the generation part.

user@myhost$ ssh-keygen -t rsa

You need to either make use of ssh-agent or use empty passphrase. Now copy the contents of ~user/.ssh/id_rsa.pub and paste them here.

2. Create empty repository on github

Here.

3. Add github as a remote

user@myhost$ cd git/myrepo.git/
user@myhost$ git remote add --mirror github git@github.com:user/myrepo.git

Push the current contents:

user@myhost$ git push github

4. Set up post-receive hook

Open hooks/post-receive and make it look like this. (post-update should work as well, but mine does update-server-info so why not use the other ...) Don't forget to make it executable.

#!/bin/sh

git push --quiet github

5. Done

Now whenever you push your changes to myrepo at myhost, they should also magically appear at github.