<blog:entry xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:blog="http://www.adamretter.org.uk/blog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.adamretter.org.uk/blog http://www.adamretter.org.uk/blog/entry.xsd" status="published" id="3725c5b6-0667-4979-8e32-93ec25a06a99">
    <blog:article timestamp="2012-08-19T12:03:00.000+01:00" author="Adam Retter" last-updated="2012-08-19T12:03:00.000+01:00">
        <blog:title>Keeping GitHub pages up to date with your master</blog:title>
        <blog:sub-title>Auto-sync from master to gh-pages</blog:sub-title>
        <blog:article-content>
            <xh:p>
                For the <xh:a href="http://exquery.github.com/exquery/exquery-restxq-specification/restxq-1.0-specification.html" title="RESTXQ 1.0: RESTful Annotations for XQuery 3.0">RESTXQ specification</xh:a>
                that I am working on as part of my <xh:a href="http://exquery.org" title="Extensions for XQuery">EXQuery</xh:a> efforts,
                I need to write up a "formal" specification for RESTXQ. 
                The EXQuery RESTXQ code base lives on GitHub
                (<xh:a href="http://github.com/exquery/exquery" title="EXQuery GitHub">http://github.com/exquery/exquery</xh:a>),
                and the specification has been authored in the <xh:code>exquery-restxq-specification</xh:code> module.
            </xh:p>
            <xh:p>
                The RESTXQ specification is authored in HTML using Robin Berjon's excellent
                <xh:a href="http://pages.github.com/darobin/respec" title="ReSpec GitHub">ReSpec</xh:a> 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.
            </xh:p>
            <xh:p>
                Fortunately GitHub provides a nice facility for web pages called
                <xh:a href="http://pages.github.com/" title="GitHub Pages">GitHub Pages</xh:a>.
                However, the pages are taken from a branch of your GitHub repository called <xh:code>gh-pages</xh:code>. The
                advantage of this is that your 'pages' can contain different content to your main source code
                base (i.e. your <xh:code>master</xh:code> branch). If your page content is in your <xh:code>master</xh:code>
                branch though, you need a facility for keeping the copy in your <xh:code>gh-pages</xh:code> branch up to date
                with your commits to <xh:code>master</xh:code>.
            </xh:p>
            <xh:p>
                I will not detail how to setup GitHub pages, that is better covered
                <xh:a href="https://help.github.com/articles/creating-project-pages-manually" title="GitHub Help: Creating Project Pages Manually">here</xh:a>.
            </xh:p>
            <xh:p>
                I simply wanted to be able to keep a single folder called <xh:code>exquery-restxq-specification</xh:code> 
                from <xh:code>master</xh:code> in sync with my <xh:code>gh-pages</xh:code>. When creating my
                <xh:code>gh-pages</xh:code> repository, following the instructions
                <xh:a href="https://help.github.com/articles/creating-project-pages-manually" title="GitHub Help: Creating Project Pages Manually">above</xh:a>,
                rather than delete everything in the <xh:code>gh-pages</xh:code> branch, I deleted everything except
                the <xh:code>exquery-restxq-specification</xh:code> folder, and then committed and pushed.
            </xh:p>
            <xh:p>
                To keep the folder in sync across both branches, we can add a post-commit hook locally to the <xh:code>master</xh:code> branch,
                so that when we commit changes to that folder in <xh:code>master</xh:code>, the changes are propagated to the
                <xh:code>gh-pages</xh:code> branch.
            </xh:p>
            <xh:p>
                To add the post-commit hook, create the script: <xh:code>your-repo/.git/hooks/post-commit</xh:code>
                <xh:pre>
    #!/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
</xh:pre>
                If you are on Linux/MacOSX/Unix, you must ensure that the script has execute permissions, otherwise Git will
                not execute it.
            </xh:p>
            <xh:p>
                Now simply changing something in the <xh:code>exquery-restxq-specification</xh:code> folder in
                the <xh:code>master</xh:code> branch and committing, will cause Git to also sync the changes
                to the <xh:code>gh-pages</xh:code> branch.<xh:br/> As a further exercise it might be interesting
                to take the commit message for <xh:code>gh-pages</xh:code> from the last commit
                message of <xh:code>master</xh:code>...
            </xh:p>
        </blog:article-content>
    </blog:article>
    <blog:tags>
        <blog:tag>XQuery</blog:tag>
        <blog:tag>Full-Text</blog:tag>
        <blog:tag>Search</blog:tag>
        <blog:tag>eXist-db</blog:tag>
    </blog:tags>
</blog:entry>