Skip to main content
GitHub Pages provides free hosting for static sites directly from your GitHub repositories. Opal Editor uses Git-based deployment to push your built sites to GitHub Pages.

Prerequisites

Before deploying to GitHub Pages:
  • A GitHub account
  • A GitHub repository for hosting your site
  • GitHub authentication (Personal Access Token or OAuth)
  • A completed build ready for deployment

Authentication Setup

Opal Editor supports multiple GitHub authentication methods:
1

Create a Personal Access Token

  1. Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
  2. Click “Generate new token (classic)”
  3. Give it a descriptive name (e.g., “Opal Editor”)
  4. Select scopes:
    • repo (full control of private repositories)
    • public_repo (for public repositories only)
  5. Click “Generate token”
  6. Copy the token immediately (it won’t be shown again)
2

Add to Opal Editor

Create a new GitHub API authentication in Opal Editor and paste your token.
Store your Personal Access Token securely. It provides access to your repositories.

OAuth

Alternative authentication methods:
  • OAuth: Browser-based authentication flow
  • Device Flow: CLI-friendly authentication without browser

Destination Configuration

Configure your GitHub Pages deployment:
{
  "remoteAuthId": "your-auth-id",
  "label": "My GitHub Pages Site",
  "meta": {
    "repository": "username/repo-name",
    "branch": "gh-pages",
    "baseUrl": "/"
  }
}

Configuration Fields

  • repository (required): GitHub repository in format owner/repo or full URL
    • Examples: username/my-site or https://github.com/username/my-site
    • Automatically normalized to owner/repo format
  • branch (required): Branch for deployment (default: gh-pages)
    • Common choices: gh-pages, main, master
  • baseUrl (required): Base URL path for your site
    • Use / for user/org pages (username.github.io)
    • Use /repo-name/ for project pages
For project repositories, the baseUrl should match your repository name: /repo-name/

Deployment Process

GitHub Pages deployment uses Git to push your built site:
1

Configure repository

Set up your deployment:
  • Specify repository (created if doesn’t exist)
  • Choose deployment branch
  • Set base URL for correct link paths
2

Build your site

Complete a build in Opal Editor:
  • Files are processed and built
  • HTML is generated
  • Assets are prepared
3

Deploy via Git

Deployment process:
  • Temporary Git repository is created
  • Built files are committed
  • Changes are force-pushed to specified branch
  • Repository is cleaned up
4

GitHub Pages activation

GitHub automatically:
  • Detects the new commit
  • Builds and deploys your site
  • Makes it available at the Pages URL
5

Access your site

Your site is live at:
  • User/Org pages: https://username.github.io
  • Project pages: https://username.github.io/repo-name

How It Works

The GitHub deployment process (RemoteAuthGithubAgent):
  1. Repository Validation: Verifies repository exists or creates it
  2. Git Initialization: Creates a temporary Git repository
  3. Commit Creation: Commits all built files
  4. Remote Push: Force-pushes to the specified branch
  5. URL Generation: Returns the GitHub Pages URL
  6. Cleanup: Removes temporary Git repository

Git-Based Deployment

Unlike other platforms, GitHub Pages uses Git:
// Deployment flow:
1. GitRepo.GHPagesRepo() // Create temp repo
2. GitPlaybook.initialCommit() // Commit files
3. GitPlaybook.pushRemoteAuth() // Push to GitHub
4. repo.dispose() // Cleanup
Key features:
  • Force push for clean deployments
  • Full file replacement each time
  • No merge conflicts
  • Complete deployment history

URL Rewriting

For non-root base URLs, Opal Editor automatically:
  • Rewrites absolute URLs in HTML files
  • Updates links to include base URL
  • Ensures assets load correctly
  • Handles script and style references
Example:
<!-- Before rewriting (baseUrl: /my-site/) -->
<link href="/style.css">

<!-- After rewriting -->
<link href="/my-site/style.css">

Repository Types

User/Organization Pages

For username.github.io repositories:
{
  "repository": "username/username.github.io",
  "branch": "main",
  "baseUrl": "/"
}
  • Must be named username.github.io
  • Deploy to main branch (or configure in settings)
  • Base URL is always /
  • Site URL: https://username.github.io

Project Pages

For project repositories:
{
  "repository": "username/my-project",
  "branch": "gh-pages",
  "baseUrl": "/my-project/"
}
  • Any repository name
  • Typically use gh-pages branch
  • Base URL must match repo name
  • Site URL: https://username.github.io/my-project

Features

Free Hosting

GitHub Pages is completely free:
  • Unlimited public repositories
  • 1GB storage limit
  • 100GB bandwidth per month
  • Custom domain support

Automatic HTTPS

All GitHub Pages sites include:
  • Free SSL certificates
  • HTTPS enforced (optional)
  • Automatic certificate renewal

Custom Domains

Configure custom domains:
  • Add CNAME file to your repository
  • Configure DNS records
  • Enable HTTPS in repository settings

Deployment History

Git-based deployment provides:
  • Complete commit history
  • Ability to view previous versions
  • Revert to earlier deployments
  • Full audit trail

Troubleshooting

Repository Not Found

If “Repository not found”:
  • Verify repository name format: owner/repo
  • Check your token has access to the repository
  • Ensure repository exists (or will be created)
  • Confirm repository is not private (unless token has repo scope)
Solution: Verify the repository name and your access permissions.

Authentication Failures

If Git push fails:
  1. Verify Personal Access Token is valid
  2. Check token has repo or public_repo scope
  3. Ensure token hasn’t expired
  4. Try regenerating the token

404 After Deployment

If site shows 404 after deployment:
  1. Enable GitHub Pages in repository settings
  2. Select correct branch (gh-pages)
  3. Wait a few minutes for GitHub to build
  4. Check repository visibility (public vs private)
  5. Verify branch contains index.html

Wrong Base URL

If styles/assets don’t load:
  • Check baseUrl matches repository name
  • For user pages, use /
  • For project pages, use /repo-name/
  • Verify HTML contains correct URLs

Force Push Issues

Deployment uses force push:
  • Previous branch history is overwritten
  • Don’t use the same branch for development
  • Use dedicated deployment branch (gh-pages)
  • Never force push to main if used for source code

Best Practices

  1. Use dedicated branch: Deploy to gh-pages, keep code in main
  2. Set correct base URL: Match repository name for project pages
  3. Enable HTTPS: Configure in repository settings
  4. Add custom domain: Use CNAME for professional URLs
  5. Monitor deployment: Check Actions tab for GitHub’s build process
  6. Test locally: Ensure build completes before deploying

Advanced Configuration

Custom Domain Setup

Add a custom domain:
1

Add CNAME file

Include a CNAME file in your build output:
www.yourdomain.com
2

Configure DNS

Add DNS records at your domain provider:
CNAME  www  username.github.io.
3

Enable HTTPS

In repository settings > Pages:
  • Verify custom domain
  • Enable “Enforce HTTPS”

Jekyll Override

Disable Jekyll processing: Add a .nojekyll file to your build output to prevent GitHub from processing your site with Jekyll.

404 Page

Create a custom 404 page: Add 404.html to your build output. GitHub Pages will serve it for missing pages.

Deployment Workflow

For automated deployments, combine with:
  • GitHub Actions for CI/CD
  • Webhook triggers
  • Scheduled deployments

Performance Optimization

CDN

GitHub Pages uses Fastly CDN:
  • Global distribution
  • Edge caching
  • Fast content delivery

Caching

Optimize caching:
  • Use versioned asset filenames
  • Set appropriate cache headers
  • Leverage browser caching

Build docs developers (and LLMs) love