After using Jekyll for quite some time now, I was looking for a way to publish to a draft website before publishing
to the live website. As I’m using a git hook to publish my websites
(see Why and how I moved from Wordpress to Jekyll: Publishing),
I was looking for a way to use git for this. Therefore I’ve written a new
post-receive hook which is able to
differentiate which branch was pushed. Depending on the pushed branch, Jekyll generates the website to a different
path, using different configuration files. A new Apache vHost can now point to this different path, serving f.e.
a basic authentication secured subdomain like
Just place the
post-receive hook to the git hooks directory on the server and change the constants at the beginning
of the script to your environment. Now create a new branch, make changes an push this branch to the same named remote branch.
The hook now generates the webpage according to the branch name. If the branch is unknown to the hook, it just
does nothing and exits with an error.
After finishing the work, merge the draft brancht to the master branch and push it, the update of the website is now live.
Jekyll is able to read more than one configuration file, separated by comma. The later configuration file overwrites
the values from the earlier one. So just add the values which are different on the draft page to the second
configuration file, f.e. the
source on gist.github.com