GitHub Pages
GitHub Pages comes in two flavors: personal pages and project pages.
- Personal page: domain is
username.github.io, whereusernamematches your GitHub username. Only the master branch of the repo can be used to build the page. - Project page: domain is
username.github.io/project, whereprojectis the repo name. You can designate any branch as the build source.
The deployment instructions below only cover personal pages. If you’ve set up a personal page before, project pages shouldn’t be a challenge.
Travis CI
GitHub has been using Travis CI for automated builds for a long time. After a certain update, GitHub started showing Travis CI build results directly on the platform.

Here, we can push the blog’s source code to GitHub, then trigger Travis CI to push the built result to the master branch of my personal page repo at rainfd.github.io.
Note: push your source code to a non-master branch, since personal pages can only use the master branch for GitHub Pages.
Deployment Steps
- Create a repo on GitHub named username.github.io.
- Add a
.gitignoreto your Hexo blog code, excluding generated static files and other irrelevant files. You can reference the file below.
db.json
*.log
node_modules/
public/
.deploy*/%
- If you’re like me and want to keep third-party themes in sync with upstream, fork the theme and add it as a submodule in your blog code.
git submodule add $url themes/your_theme
- Sign up for Travis CI and authorize it.
- In Applications settings, configure Travis CI to grant access to your
username.github.iorepo. - After configuration, you’ll be redirected to the Travis CI page.
- Create a new Token on GitHub with at least all repo-level permissions.
- Go back to the Travis CI page (or re-login), and set the token you just created as the environment variable GH_TOKEN on the corresponding Travis repo. Remember to save.
- Add the
.travis.ymlconfig file to your blog code (I use thesourcebranch to store source code).
sudo: false
language: node_js
node_js:
- 10 # use nodejs v10 LTS
cache: npm
branches:
only: # only trigger builds when these branches change
- source # build master branch only
script:
- hexo generate # generate static files
deploy:
provider: pages
skip-cleanup: true
github-token: $GH_TOKEN
keep-history: true
on: # which branch to build from
branch: source
target_branch: master # target branch for deployment, defaults to gh-pages
local-dir: public # deployment target directory
Hexo’s Travis CI deployment guide: https://hexo.io/docs/github-pages Travis CI GitHub Pages deployment config reference: https://docs.travis-ci.com/user/deployment/pages/
- This is for cases where your blog code also contains the original theme.
- Push the code to the branch where you store your source (remember: it cannot be the master branch).
- Wait for the Travis build to finish. You can also click the icon next to the project name to view build progress.

- If the build fails for the following reason, delete line 77 of the corresponding file (because GitHub Pages uses Jekyll as its default build template, and the syntax on line 77 conflicts with Jekyll’s syntax).

- Finally, visit
username.github.ioto check your blog.