botbotbot 's blog

Jekyll build with Travis and deploy to Github Page

Github Pages Tips:
Github Pages always complie jekyll with --safe option that will
disable plugins but some plugin can work with Github Pages.
List of Jekyll Plguins that working on Github > Pages

To avoid this --safe option to be powerful jekyll, you need to build your jelyll somewhere else and commit your static page to main or gh-page branch. We can automate build jekyll with Travis-CI that store your jekyll file in jekyll branch when push to github that will trig to Travis to build and deploy static page back to your main branch to publish your contents. you should read previous blog about jekyll and travis

Good to knows:

  1. Should backup your repository in somewhere else, this method need to in your local repository and your github repository.
  2. In your .travis.yml always keep > /dev/null 2>&1 to avoid your tokens display on logs or you can remove for debugging git push.
  3. Github page need verified email for trigger update contents.
  4. You can check your last build from feed.xml on Jekyll
  5. If your use Github page as personal page don’t try to change Default branch on your Github repository settings that will use your Default branch to hosting your page.

How to:

Verified by Mildronize

  1. Create jekyll branch for development

    $ git branch jekyll
  2. Clear your main or gh-page branch to blank

    $ git rm *
  3. Enable Travis on your repository on Travis website and turn on Build only if .travis.yml is present on your travis repository settings.
  4. Checkout jekyll branch and create .travis.yml then edit GH_REF and TARGET_BRANCH to your own

    $ git checkout jekyll


    sudo: false
    language: ruby
    - 2.2
      - jekyll
    - bundle exec jekyll build
    - bundle exec htmlproofer ./_site --disable-external
    - git clone https://$GH_REF
    - cd $(basename ${GH_REF%.git})
    - git config "Travis-CI"
    - git config ${EMAIL}
    - rsync -az --delete --exclude '.git*' ../_site/ .
    - touch .nojekyll
    - git add -A .
    - git commit -m "Generated Jekyll Site by Travis CI - ${TRAVIS_BUILD_NUMBER}"
    - git push -f "https://${DEPLOY_KEY}@${GH_REF}" ${TARGET_BRANCH} > /dev/null 2>&1
      - GH_REF:
      - TARGET_BRANCH: master
  5. Create your Github Personal Access Tokens - check only repo that enough.
  6. Install Travis Gem on your machine for encryption sensitive data

    $ gem install travis
  7. Encrypt your EMAIL and DEPLOY_KEY

    # --add opton will automated add sescure data to your .travis.yml
    # edit verifiedemail to your github email account
    $ travis encrypt EMAIL=verifiedemail --add
    # edit githubtoken to your github personal access tokens
    $ travis encrpy DEPLOY_KEY=githubtoken --add
  8. Commit jekyll branch

    $ git add -A
    $ git commit -m "Create Jekyll branch for build jekyll with Travis"
  9. Push to jekyll branch to Github repository and wait

    $ git push origin jekyll
    # Don't care warnning about main/gh-page branch that local repository out of date
  10. Look your published site

Demo Repository

I use develop branch as jekyll and I’m lazy to change but I recommend to use jekyll branch should be better.


# config local git repo to push only current active branch
$ git config push.default simple


  1. Auto-deploying built products to gh-pages with Travis
  2. Publishing gh-pages with Travis-CI
  3. Automate GitHub Pages publishing with Jekyll and Travis CI
  4. Troubleshooting GitHub Pages build failures
  5. Travis Custom Deployment
  6. Travis Encryption keys
  7. Creating an access token for command-line use
  8. Bypassing Jekyll on GitHub Pages