No Hair Blog

Using git to manage a static blog

I edit my blog using a desktop Mac, a Macbook, and an iPad. Now I use ssh and TextWrangler on the Macs and Textastic on the iPad. But if I'm not connected, I'm out of luck. In addition, I am actually editing the live site, which has the potential for disaster. I wanted to have the ability to edit and post to the site while offline, have some degree of version control to roll back mistakes and as well as have backups if the webserver crashes or I screw up by deleting some file.

I decided to use git to manage the blog so I can have multiple machines editing and some degree of distributed backup. There are a number of articles on the web regarding this (for example, here), but my system is a little bit different.

Setting up the web server

For the server running OpenBSD with httpd as the web server, the workflow is this:

httpd web root <<- devel.repo.git<--> remote computers

Here, the git repo "devel.repo.git" acts as the central repository. The remote repos on the client machines are clones of the devel.repo.git. After edits, commits are pushed to the devel.repo.git master. A post-receive hook checks out the files to the web server www document root (see below).

So to set up the OpenBSD box:

1. Set up passwordless ssh using shared keys: This is well-described in multiple sources. For the iPad, there are some quirks (see below).

2. Install git: By the usual package system:

pkg_add -v git

3. Create git repos:

First, create the shared development repo that the remote users will clone and push to. This should be a bare repository. This will have a post-receive script to checkout the HTML and other files to the web document root. Another non-bare repository is also created to act as a backup repo and initial source of the files in the central shared bare repo.

cd ~/blog/git-repos/

git init --bare
touch hooks/post-receive
chmod 755 hooks/post-receive

cd ../
git init
cp -R /var/www/htdocs/vhosts/blog/* .
git add -A
git commit -a -m "Initial commit"
git remote add devel /home/user/blog/git-repos/
git push devel master

4. Post-receive script:

For devel.repo.git/hooks/post-receive:

GIT_WORK_TREE=/path/to/webroot/of/website git checkout -f --

The "--" in git-checkout acts to only checkout the changed files.

Setting up a Mac client

First, git (part of the xcode command line tools) is installed. Then, be sure passwordless ssh access with private/public keys to your server works. A key passphrase should be used. Next, the devel repository is cloned and TextWrangler is set as the editor. To do this, be sure the command line tools for TextWrangler need are installed. (You can check by seeing if /usr/local/bin/edit exists.):

cd ~
mkdir git-repos
cd git-repo
git clone ssh://user@
git config --global core.editor /usr/local/bin/edit

Now, the terminal can be used to manage the repo with TextWrangler as the editor as before. To edit a file if you'e working in the repo directory, simply enter in the terminal:

edit ./post_template.html

TextWrangler pops up with the file open, edit it, and save. Now, go back to the terminal and check "git status" and you will see the new file or modified file. Then, it's a matter of "git add new_filename.html" or "git add -a" followed by "git commit." Finally, when all your work is done, "git push." The commit to the devel.repo.git on the web server updates the web site.

Setting up the iPad

The apps used are Textastic as an editor and Working Copy as a git client.

First, set up passwordless ssh access to the webserver. Working Copy (WC) tends to be very fastidious about the private key for the server. It says it must be in OpenSSH format yet rejects keys made with "keygen -o" on both the Mac and OpenBSD. The best approach is just to use or generate keys in WC and export the public key to the server.

Once you have this set up, clone the devel repo. When you select a file to edit, simply select "Open in Textastic" from the Share menu on the top right and the file opens in the Textastic editor. As you edit (the actual file in the WC silo), the changes appear in WC. No need to save or share back - pretty slick.

Then it's the usual git commit and git push in WC. The web site updates seamlessly. With this set up, it's now easier to manage the blog from the iPad than the desktop!

Final thoughts

Important: Remember, when you're editing from multiple device or locations, to "git pull" to get the current master before you start up on a new edit!

Posted by Gordon, No Hair Blog, Apr 15, 2018

© and the author

For comments, corrections, and addenda, email: gordon[AT]

Blog | Entries | Tags | Home