Search code examples
gitjekyllgithub-pages

Creating project documentation for java web project in gh-pages


I have a maven based java web project with source code in master branch. I want to create documentation for that project using jekyll, and commit the documentation along with the source in docs folder.

So, I initialized a new jekyll site named docs in my root of my project

 $ jekyll new docs

Now I have a docs folder within my project root, from where I can generate and serve the documentation.

 $ cd docs
 $ jekyll build 

All that is good and I have docs/_site folder with the generated HTML in it. How can I push this generated HTML to gh-pages branch ? Does, github provide anyway to do that? Any ideas/suggestions/best practices re:this?

EDIT

The main problem is that my jekyll code is in master and not in gh-pages branch. From the documentation at github I understand that I need to push the jekyll site to gh-pages directory.

Please correct me if I misunderstood.


Solution

  • The trick is to get your generated pages over to your gh-pages branch. One way of doing that would be to copy docs/_site to temporary location, then switch to gh-pages and copy the files over there:

    $ cp -R docs/_site /tmp/      # Copy web page files to temporary location
    $ git checkout gh-pages       # Checkout gh-pages branch
    $ git rm -rf .                # Delete existing files
    $ mv /tmp/_site/* .           # Move web page files to repo
    $ git add -A                  # Add new files
    $ git commit                  # Commit new files
    $ git push origin gh-pages    # Push changes back to GitHub