GitHub Pages Action
[!NOTE]
See also the GitHub official GitHub Pages Action first.
This is a GitHub Action to deploy your static files to GitHub Pages. This deploy action can be combined simply and freely with Static Site Generators. (Hugo, MkDocs, Gatsby, mdBook, Next, Nuxt, and so on.)
The next example step will deploy ./public directory to the remote gh-pages branch.
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
For newbies of GitHub Actions:
Note that the GITHUB_TOKEN is NOT a personal access token.
A GitHub Actions runner automatically creates a GITHUB_TOKEN secret to authenticate in your workflow.
So, you can start to deploy immediately without any configuration.
Supported Tokens
Three tokens are supported.
| Token | Private repo | Public repo | Protocol | Setup |
|---|---|---|---|---|
github_token |
✅️ | ✅️ | HTTPS | Unnecessary |
deploy_key |
✅️ | ✅️ | SSH | Necessary |
personal_token |
✅️ | ✅️ | HTTPS | Necessary |
Notes: Actually, the GITHUB_TOKEN works for deploying to GitHub Pages but it has still some limitations.
For the first deployment, we need to select the gh-pages branch or another branch on the repository settings tab.
See First Deployment with GITHUB_TOKEN
Supported Platforms
All Actions runners: Linux (Ubuntu), macOS, and Windows are supported.
| runs-on | github_token |
deploy_key |
personal_token |
|---|---|---|---|
| ubuntu-22.04 | ✅️ | ✅️ | ✅️ |
| ubuntu-20.04 | ✅️ | ✅️ | ✅️ |
| ubuntu-latest | ✅️ | ✅️ | ✅️ |
| macos-latest | ✅️ | ✅️ | ✅️ |
| windows-latest | ✅️ | (2) | ✅️ |
- WIP, See Issue #87
GitHub Enterprise Server Support
✅️ GitHub Enterprise Server is supported above 2.22.6.
Note that the GITHUB_TOKEN that is created by the runner might not inherently have push/publish privileges on GHES. You might need to create/request a technical user with write permissions to your target repository.
Table of Contents
- Getting started
- Options
- ⭐️ Set Runner's Access Token
github_token - ⭐️ Set SSH Private Key
deploy_key - ⭐️ Set Personal Access Token
personal_token - ⭐️ Set Another GitHub Pages Branch
publish_branch - ⭐️ Source Directory
publish_dir - ⭐️ Deploy to Subdirectory
destination_dir - ⭐️ Filter publishing assets
exclude_assets - ⭐️ Add CNAME file
cname - ⭐️ Enable Built-in Jekyll
enable_jekyll - ⭐️ Allow empty commits
allow_empty_commit - ⭐️ Keeping existing files
keep_files - ⭐️ Deploy to external repository
external_repository - ⭐️ Force orphan
force_orphan - ⭐️ Set Git username and email
- ⭐️ Set custom commit message
- ⭐️ Create Git tag
- ⭐️ Set Runner's Access Token
- Tips and FAQ
- Examples
- License
- Maintainer
Getting started
Add your workflow file .github/workflows/gh-pages.yml and push it to your remote default branch.
Here is an example workflow for Hugo.
name: GitHub Pages
on:
push:
branches:
- main # Set a branch name to trigger deployment
pull_request:
jobs:
deploy:
runs-on: ubuntu-22.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.110.0'
- name: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
# If you're changing the branch from main,
# also change the `main` in `refs/heads/main`
# below accordingly.
if: github.ref == 'refs/heads/main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
| Actions log overview | GitHub Pages log |
|---|---|
![]() |
![]() |
Options
⭐️ Set Runner's Access Token github_token
This option is for GITHUB_TOKEN, not a personal access token.
A GitHub Actions runner automatically creates a GITHUB_TOKEN secret to use in your workflow. You can use the GITHUB_TOKEN to authenticate in a workflow run.
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
For more details about GITHUB_TOKEN: Automatic token authentication - GitHub Docs
⭐️ Set SSH Private Key deploy_key
Read Create SSH Deploy Key, create your SSH deploy key, and set the deploy_key option like the following.
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./public
⭐️ Set Personal Access Token personal_token
Generate a personal access token (repo) and add it to

