我要啦免费统计

How to Deploy Hexo on Github Pages

This is a step-by-step guide on how to deploy Hexo on Github Pages. I will use the configurations of this Hexo blog as an example.

Preparation

  • Install git.
  • Install node-js.
  • Install Hexo.

On Hexo’s website, there is a very detailed guide on how to finish the above three steps.

  • Create a Github repository so that we can host Hexo generated blog pages by pushing them to the gh-pages branch.

Setup

Clone the created “blog” repository to local.

1
$ git clone https://github.com/anilot/blog.git

Initialize Hexo

1
2
3
$ cd blog
$ hexo init
$ npm install

Change configurations

Open _config.yml, and edit the configurations.

Note: since we will deploy the blog to the gh-pages branch of the “blog” repository, we are actually deploying Hexo to a subdirectory called “blog” under anilot.github.io. Hence we need to change the url settings.

1
2
url: http://anilot.github.io/blog
root: /blog/

Also we need to change the deploy method so that Hexo can directly push the blog to Github.

1
2
3
4
deploy:
type: github
repo: https://github.com/Anilot/blog.git
branch: gh-pages

Deploy to Github Pages

1
$ hexo deploy --generate

Enter your Github username and password.
Then we can access the blog at http://anilot.github.io/blog.

If you have any questions, feel free to leave a comment below.