Hexo - How to backup configs and blogs of Github Pages in a Github repository

Github Pages is great - it allows you to set up static website on it and use it as a blog.

I’ve been using Hexo as the blogging platform and static website generator, and NexT as its theme. One thing I really need when using Hexo is to back up all my blogs which are in markdown format, as well as Hexo configuration file, a bunch website configuration files, and the theme configuration file. The reason being that 1) self-managed blog generator is very easy to be messed up, and 2) I need to re-setup everything when switching computers, both cases requiring reconfigure Hexo and restore all contents and configurations.

So wouldn’t it be nice that we can use your .github.io repository for Github Pages, and another repository, say Hexo, for all your blogs and configurations?

It’s a bit tricky, and I’m gonna show you how to do it.

Backgrounds - What files should be backed up

Let’s say Hexo lives in a dir called Hexo, and your theme is NexT, the file layout looks like this:

- Hexo
- _config.yml (Hexo config file)
- node_modules (Node.js code of Hexo and all plugins)
- public (generated static website data)
- scaffolds (template files)
- source
- _posts (all your blogs)
- (other top-level sites you want to add, like **about**, **categories**, and **tags**)
- themes (Hexo themes)
- landscape (Hexo default theme)
- next (NexT theme)
- _config.yml (NexT's config file)

0. Make sure you have installed hexo

Check this post

1. Init Hexo in a temp folder

Let’s init Hexo in a temp folder called hexocopy

mkdir hexocopy
cd hexocopy
hexo init

2. Init your official Hexo repository

  • Create a repository called Hexo, or clone your already existing ‘Hexo’ repository to your local machine with git clone

    git clone https://github.com/bowenli86/Hexo

3. Copy files

Copy _config.yml, node_modules, and themes folders from hexocopy to Hexo.

The reason for not initing Hexo itself from dir Hexo is that, command init Hexo will clone bits from a git repository and it will overwrite .git of the Hexo repository.


  • for _config.yml files, carefully merge the old one with the new one since configs may be incompatible over time. Also make sure their versions are correct!! Otherwise, Hexo won’t be able to process template and generate sites.
  • several files should not be overriden, like scaffolds/post.md, etc

4. Continue

Then, refer to this post to continue setting up plugins, themes, and configs.