Pushing jekyll blog content to Dreamhost using GIT

Posted on March 24, 2014

Keeping the blog versioned

Initially I forked a theme and started tweaking it. Since with static content blogs you don’t need a database I created a git repo to store jekyll’s folder structure and assets.
Also I added a remote private repo in bitbucket (I don’t want anybody to see _config.yml for example).

The initial workflow

The initial workflow was to generate the static content, open a ftp connection and upload the contents of the _site folder.
That was OK but since I spend most of my time on the console, having the possibility to push updates to my blog using GIT sounded like a good idea.
The question was if that was actually possible with Dreamhost.

Remote repo creation

Setting up the post-receive hook

After we initialize the bare repo we need to set up a post-receive hook, that will be triggered every time changes are pushed.
The thing here changes a little from the gist I found. Since Jekyll’s default build folder is _site and I want to keep all in one repo I added some extra steps to the hook.
The other way to do this would be keeping a simple hook but pointing Jekyll’s build to other folder, if that works for you is not very different than this.

We need to connect to the server again and create a post-receive hook using vi (or the editor you like):

Creating the remote structure

Now we need to create a remote structure.
In Dreamhost, we clone the repo we just created:

$ cd ..
$ git clone <mydomain_com>.git <mydomain.com>-jekyll

The flow is:
Once the changes are pushed, the entire Jekyll folder structure will be sitting on a directory -jekyll.
Then the hook will be copying just the static content to your actual directory that is open to the public.

Adding the remote endpoint to our local repository and pushing changes

In our machine we need to add the remote to our local repository.

$ git remote add live ssh://<user>@<host>/~/<mydomain_com>.git

And that’s it.

We will now be able to push changes straight to our Dreamhost domain with: