Keeping GitHub pages up to date with your master
Auto-sync from master to gh-pages
For the RESTXQ specification
that I am working on as part of my EXQuery efforts,
I need to write up a "formal" specification for RESTXQ.
The EXQuery RESTXQ code base lives on GitHub
(http://github.com/exquery/exquery),
and the specification has been authored in the exquery-restxq-specification module.
The RESTXQ specification is authored in HTML using Robin Berjon's excellent
ReSpec tool.
As specifications are arguably meant to be read by people, it would be nice if we could present the
work in progress from the source repository to users as a web page.
Fortunately GitHub provides a nice facility for web pages called
GitHub Pages.
However, the pages are taken from a branch of your GitHub repository called gh-pages. The
advantage of this is that your 'pages' can contain different content to your main source code
base (i.e. your master branch). If your page content is in your master
branch though, you need a facility for keeping the copy in your gh-pages branch up to date
with your commits to master.
I will not detail how to setup GitHub pages, that is better covered
here.
I simply wanted to be able to keep a single folder called exquery-restxq-specification
from master in sync with my gh-pages. When creating my
gh-pages repository, following the instructions
above,
rather than delete everything in the gh-pages branch, I deleted everything except
the exquery-restxq-specification folder, and then committed and pushed.
To keep the folder in sync across both branches, we can add a post-commit hook locally to the master branch,
so that when we commit changes to that folder in master, the changes are propagated to the
gh-pages branch.
To add the post-commit hook, create the script: your-repo/.git/hooks/post-commit
#!/bin/sh
git checkout gh-pages #switch to gh-pages branch
git checkout master -- exquery-restxq-specification #checkout just the exquery-restxq-specification folder from master
git commit -m "Merge in of specification from master branch" #commit the changes
# git push #uncomment if you want to auto-push
git checkout master #switch back to the master branch
If you are on Linux/MacOSX/Unix, you must ensure that the script has execute permissions, otherwise Git will
not execute it.
Now simply changing something in the exquery-restxq-specification folder in
the master branch and committing, will cause Git to also sync the changes
to the gh-pages branch. As a further exercise it might be interesting
to take the commit message for gh-pages from the last commit
message of master...
XQuery
Full-Text
Search
eXist-db