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 https://git.gitbook.com/user/repos.git
git push --mirror https://github.com/user/repos.git
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 ) https://github.com/tpmccallum/bitnami-wordpress-backup-to-dropbox
We can now clone the new Github repository to our local machine
git clone https://github.com/user/repos.git
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/id_rsa.pub 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 firstname.lastname@example.org
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 email@example.com:user/repos.git
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 firstname.lastname@example.org 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
echo -e $string