Blog now in Git

Here’s something that was on The List for a long time: adding this blog to a git-repository. Why did that take so long?

I wanted to have my own, personal git-server instead of GitHub to push stuff to, so I can have a post-hook do cool stuff like auto-deploy the website. That is possible with GitHub as well (if you pay for it), but I thought it would be ‘fun’ to play around with all this ๐Ÿค“

My workflow used to be:

  • write article & jekyll serve
  • when satisfied: do a complicated rsync-command (hidden behind an alias)

My new workflow:

  • write article & jekyll serve
  • make commits while writing
  • when satisfied: git push

My server then checks out the most recent commit, runs jekyll build and rsyncs the new items. Because that happens automatically it’s a lot less fault-sensitive.

You are now reading the first article published with git push ๐Ÿ˜‡. Currently only matth-ijs.nl works like this, but in the near future I’ll port 1001ideas.org as well.

My setup #

I’ve installed both git and jekyll on my VPS and added a new user there (git). In the home-folder of git I’ve setup blank repositories for all my projects (like this site). On my local machine I created a new RSA-key specifically for the git user (not strictly necessary, but I was in an experimenting mood).

I then created a new repository for this blog locally, added all files and set the origin to the server. Done!

Steps #

Remote:

  • in the home-folder of your git user: git init --bare <sitename>
  • add script to the hooks-folder (see below)
  • make a var/www/<sitename>/public_html which is owned by the right user
  • add virtual-server for Apache for that folder

Local:

  • git init in the right folder
  • git remote add origin <ssh-credentials>:<sitename>
  • git push --set-upstream origin master
Script #
#!/bin/sh
site="1001ideas.org"
mkdir /tmp/${site}
rm -rf /tmp/${site}/*
git --work-tree=/tmp/${site} --git-dir=/home/git/${site} checkout -f
cd /tmp/${site}
jekyll build
rsync -av _site/ /var/www/${site}/public_html/ --itemize-changes