In this tutorial, we use GitHub Actions to deploy GitHub Pages. It works in both public and private repositories. Skip to the One-command deployment section if you prefer not to upload your source folder to GitHub.
- Create a repo named username.github.io, where username is your username on GitHub. If you have already uploaded to another repo, rename the repo instead.
- Push the files of your Hexo folder to the default branch of your repository. The default branch is usually main, older repositories may use master branch.
To push
main
branch to GitHub:$ git push -u origin main
The
public/
folder is not (and should not be) uploaded by default, make sure the.gitignore
file containspublic/
line. The folder structure should be roughly similar to this repo.
- Check what version of Node.js you are using on your local machine with
node --version
. Make a note of the major version (e.g.,v20.y.z
) - In your GitHub repo’s setting, navigate to Settings > Pages > Source. Change the source to GitHub Actions and save.
- Create
.github/workflows/pages.yml
in your repo with the following contents (substituting20
to the major version of Node.js that you noted in previous step):
name: Pages |
- Once the deployment is finished, check the webpage at username.github.io.
Note - if you specify a custom domain name with a CNAME
, you need to add the CNAME
file to the source/
folder. More info.
Project page
If you prefer to have a project page on GitHub:
- Navigate to your repo on GitHub. Go to the Settings tab. Change the Repository name so your blog is available at username.github.io/repository, repository can be any name, like blog or hexo.
- Edit your _config.yml, change the
url:
value to https://username.github.io/repository. - In your GitHub repo’s setting, navigate to Settings > Pages > Source. Change the source to GitHub Actions and save.
- Commit and push to the default branch.
- Once the deployment is finished, check the webpage at username.github.io/repository.
One-command deployment
The following instruction is adapted from one-command deployment page.
- Install hexo-deployer-git.
- Add the following configurations to _config.yml, (remove existing lines if any).
deploy: |
- Run
hexo clean && hexo deploy
. - Check the webpage at username.github.io.