Automating Github housekeeping on local Ubuntu machine

I am writing a book in Github, I was using Gitbook and decided to move it accross to Github for more GIT functionality and automated backups etc

If you already have a book in Gitbook (like me) you will need to transfer the git book to git hub. I am doing this manually with Git commands rather than relying on the web interface which I believe can import a Gitbook into Github etc.

Transfering an existing Gitbook to Github

git clone --bare

cd repos.git

git push --mirror

cd ..

rm -rf repos.git

Now here comes the best part – the functionality/automated backups to a local machine and Dropbox ( I have some other code over on Github which transfers files to my Dropbox account using the Dropbox APIs )

We can now clone the new Github repository to our local machine

git clone

If you generate a key on your local machine like this we can start automating communication between the systems


Copy the contents of the public key (which will now be in the /home/ubuntu/.ssh/ file on your computer, if you are running Ubuntu like me) to Github (click on the gear icon in Github and select SSH keys from the menu).

Test the connection using the following command (use git@ not your username, this is deliberate)

ssh -T

Change the Git URL to the SSH URL not the HTTP URL (or you could have simply cloned using the SSH option on your Github page)

git remote set-url origin

Now write some BASH and perform what ever Git commands you want to. I will be setting Cron jobs for example fetching changes on the hour and sending a backup to my Dropbox account daily etc.

My simple bash script is below, I did have a few issues getting it working using Cron …

I found that I had to re run ssh in order for it to accept the key exchange on one of my private repositories


For some strange reason the .git/FETCH_HEAD file was owned by root (perhaps because the repository is private. In my case I had to
sudo chown ubuntu:ubuntu repos/.git/FETCH_HEAD
on my local copy of the repository in order for it to work


#just initializes private/public key

#add for each repos which you want to update
string=”\n repos-name”
echo -e $string
cd /home/ubuntu/repos-name
git pull


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s