Skip to main content

Deploy to GitHub Pages (preview)

Preview, switched off in this version

Deploying to GitHub Pages from the panel is not available in this version yet. Under Where should the site go? the panel shows GitHub Pages with the badge Coming soon, and the tab cannot be chosen. wp oh-my-etch static-export deploy github refuses with GitHub Pages deployment is not available in this version yet.

To host the site on GitHub Pages today, export it as a ZIP file with the site address from the table below, and upload the unzipped files to the repository yourself.

The rest of this page describes the preview. You can turn it on for testing by adding this line to wp-config.php:

define( 'OME_STATIC_EXPORT_GITHUB_PREVIEW', true );

Use it at your own risk. The preview may change or be removed in any release, and nothing on this page is promised to stay as described.

Beta

Static Export is in beta. See what Beta means.

With the preview on, the GitHub Pages destination of the Static Export panel commits your last finished export to a branch of a GitHub repository and turns on GitHub Pages for it. This page walks through the token, the first deployment, and what happens on later ones.

Under Where should the site go?, choose GitHub Pages, now marked Preview. It has three numbered steps:

  1. Connect GitHub: connect a token. The step shows Done once it is connected.
  2. Export the site: enter the Site address on the static host, choose what to record under Filters (see Choose what is recorded), then click Export site. See Before you start: the site address.
  3. Deploy: choose the repository and branch, test the connection and deploy. Until GitHub is connected, this step says Connect GitHub first, then deploy.

Switching to another destination stops nothing. A deployment that is running goes on, and the GitHub Pages destination is marked Deploying… meanwhile.

Before you start: the site address​

GitHub Pages serves a repository in one of these places. Export with the matching Site address on the static host (step 2 of GitHub Pages, or Folder path under Served from a folder? in step 1 of ZIP file):

RepositoryAddress on GitHub PagesSite address to export with
A project repository, such as octo-org/my-sitehttps://octo-org.github.io/my-site//my-site
The user or organization site, octo-org/octo-org.github.iohttps://octo-org.github.io/Leave empty
Any repository with a custom domain set in its Pages settingsYour domainLeave empty

The deployment checks this. When GitHub Pages is on and the export was made for another path, the deployment is refused; see Exported for another address.

Create the token​

Use a fine-grained personal access token limited to the one repository you deploy to.

  1. On GitHub, open Settings → Developer settings → Personal access tokens → Fine-grained tokens and create a new token.
  2. Set an expiry date.
  3. Under repository access, choose only the one repository you deploy to.
  4. Give it these repository permissions:
    • Contents: Read and write
    • Pages: Read and write
  5. Optional: Administration: Read and write. It only lets the plugin switch GitHub Pages on for you. Without it, switch GitHub Pages on once by hand (see Switch GitHub Pages on by hand).
  6. GitHub adds Metadata: Read-only by itself.
  7. Generate the token and copy it.

The most secure setup is to put the token in wp-config.php instead of pasting it into the panel, so it never enters the database:

define( 'OME_STATIC_EXPORT_GITHUB_TOKEN', 'github_pat_…' );

See Keeping tokens safe.

Connect​

If you defined the token in wp-config.php, step 1 already reads Connected and says the token can only be changed there. Skip to the next step.

Otherwise:

  1. Paste the token into Token.
  2. Click Connect.

The status changes to Connected. Saving only stores the token on this site, encrypted; it is not sent to GitHub yet and is never shown again. Replace token and Disconnect appear under it.

Choose the repository and branch​

These fields are in step 3, Deploy.

  1. Enter the Owner (the GitHub user or organization) and the Repository name. You can also paste owner/repo or the repository's address into either field to fill both.
  2. Optional: enter a Branch. This is the branch GitHub Pages publishes from, at its root folder. Leave it empty to use gh-pages.
  3. Click Save repository.
  4. Click Test connection.

The test asks GitHub whether the token works, what it may do in the repository, and whether GitHub Pages is on. Connection works lists the repository (public or private), whether the branch exists, whether GitHub Pages is on and from which branch and folder, and the address the site will have. It also warns about anything that would stop the deployment, for example:

  • Export again for this address, when the last export was made for another path. It names the value to enter in Site address on the static host.
  • The repository is private. GitHub Pages on a private repository needs a paid GitHub plan.
  • The repository is archived, or the token may not push to it.
  • GitHub Pages is off, publishes with a GitHub Actions workflow, or publishes from another branch or folder.

Deploy​

In step 3, click Deploy to GitHub Pages.

The panel shows Deployment in progress and the step it is on: checking files, Comparing with what is on the branch…, uploading files, Making the commit…, then Waiting for GitHub Pages to publish the site….

note

Keep this browser tab and the panel open until the deployment finishes. If you close either, the deployment pauses. Open the panel again and click Continue deployment, or Cancel deployment.

When it is done, the panel shows Deployed to GitHub Pages, the address (The site is live at …), the commit, and how many files were uploaded and how many were already on the branch.

What a deployment does on GitHub:

  • The export becomes the whole content of the branch, in one commit. The branch's history is kept.
  • If the branch does not exist yet, the first deployment creates it.
  • The deployment adds a .nojekyll file, so GitHub Pages serves the files as they are. When a custom domain is set in the repository's Pages settings, it also writes the CNAME file, so the domain is kept.
  • If GitHub Pages is off and the token has Administration: Read and write, the deployment switches it on for the branch, root folder.
  • It waits up to 10 minutes for GitHub Pages to publish. If Pages has not finished by then, the deployment still ends as deployed, with the warning GitHub Pages is still publishing. Check the repository's Settings → Pages a few minutes later.
  • Nothing on GitHub is ever deleted, and a branch is never force-pushed.

An empty repository​

A repository without any commit is fine. The first deployment creates the Pages branch as the repository's first branch, so GitHub makes it the repository's default branch. If you add another branch later and want it as the default, change the default branch in the repository's settings.

Sites with many files​

GitHub receives the files one by one, about one per second. When more than 600 files must be sent, the deployment warns Uploading is slow. The first deployment of a large site can take a while; later ones send only the files that changed.

Later deployments​

Export again, then click Deploy to GitHub Pages again.

  • Only the files that changed since the branch's last commit are sent. Everything else is reused.
  • When the branch already holds exactly this export, committed by this site, no new commit is made. The command line says The branch … already holds this export, so nothing was committed.

When the branch holds commits from elsewhere​

The plugin replaces a branch only when this site made its last commit. If someone else committed to the branch, or it is an existing branch you chose, the deployment stops and asks first:

Replace the files on the branch gh-pages? The branch gh-pages of octo-org/my-site, at commit 1a2b3c4, has content that was not deployed by this site; deploying adds a commit that replaces its files with this export, and the branch's history is kept.

Because the history is kept, the earlier files can still be restored from it.

  • Replace its files and deploy goes ahead. Your consent covers exactly that commit.
  • Keep the branch stops. Nothing is deployed and the branch stays as it is. To deploy without replacing it, choose another branch.

If the branch moves again before the deployment starts, the dialog shows This changed since you confirmed. with the old and new commit. Check the branch and confirm again, or keep it.

Exported for another address​

When GitHub Pages is on and serves the repository at another path than the export was made for, the deployment is refused:

This export was made to be served at /, but GitHub Pages serves octo-org/my-site at https://octo-org.github.io/my-site/, so its links would not work there. Export again with the target base /my-site, then deploy.

Export again with Site address on the static host set to the value the message names (/my-site here), then deploy. While GitHub Pages is still off, the same message appears as the warning Exported for another address and the deployment goes ahead.

A protected branch​

If a branch protection rule or ruleset forbids the token to push, the deployment fails with GitHub refused to update the branch:

GitHub refused the branch gh-pages, which nobody else changed: a branch protection rule or ruleset may forbid this token from pushing to it. GitHub says: …

The text after GitHub says: is GitHub's own reason. Allow the push in the repository's rules, or deploy to another branch.

Switch GitHub Pages on by hand​

Without the Administration permission, the first deployment commits the site and then warns GitHub Pages is not on. In the repository on GitHub:

  1. Open Settings → Pages.
  2. Under Build and deployment, choose Deploy from a branch.
  3. Choose the branch you deploy to and the folder / (root), and save.

If Pages is set to GitHub Actions, the deployment is refused, because a branch would not be published. Change the source to Deploy from a branch.

Cancel or dismiss​

Cancel deployment stops a running deployment. Nothing already published on GitHub Pages is removed. If the request that updates the branch was already on its way, the branch can still receive the commit; the next deployment updates it without asking.

When a deployment has ended, Dismiss removes its result from the panel. It does not change anything on GitHub.

Disconnect​

Disconnect deletes the saved token from this site. The repository and what GitHub Pages serves are not changed. A running deployment stops. To deploy again, connect a token again. A token in wp-config.php can only be removed there.

Revoke the token on GitHub as well when you no longer need it.

Limits​

  • At most 100,000 files per deployment, because GitHub lists at most that many files of a branch.
  • At most 1 GB for the whole site, GitHub Pages' limit for a published site.
  • At most 25 MiB per file.

When an export is over a limit, the deployment is refused before anything is sent. See Troubleshooting.

To deploy from a terminal, see wp oh-my-etch static-export deploy github.