GitHub Pages

Beginner · 24 min

Publish a static site from a repository: choose a branch or a GitHub Actions workflow as the source, know the limits, and keep unwanted files out.

Before thisCreating and publishing a repositoryBranch protection and rulesets

Corey Schafer · 24 min

GitHub Pages

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Corey SchaferReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • GitHub Pages serves static files from a repository, either from a branch and folder or from the output of a GitHub Actions workflow.
  • Publishing from GitHub Actions lets you build the site first, for example run tests and a build script, and publish only the output directory.
  • A Pages deploy job needs pages: write and id-token: write permissions and a github-pages environment, and it must run after the build job.
  • Pages is static hosting only, with a site size limit, a soft bandwidth limit and rules against running a commercial service on it.
  • Everything you publish is public on the web, so never put secrets in the published directory.

Hosting without a server

Say the notes project grows a small web page that lists notes. To show it to anyone, you would normally rent a server, install a web server, and copy files across. For a page that is only HTML, CSS and JavaScript, that is a lot of machinery.

GitHub Pages removes it. It takes static files from your repository and serves them at a URL. “Static” means the files are sent as they are, with no code running on the server per request. That fits documentation sites, portfolios, project pages and anything built ahead of time by a tool such as a static site generator.

Two ways to publish

In the repository, go to Settings, then Pages under “Code, planning, and automation”. Under “Build and deployment”, the Source setting offers two choices.

Deploy from a branch. Pick a branch and optionally a folder, then Save. GitHub serves what is on that branch. It is the simplest route: commit the HTML, push, and it appears. The cost is that generated output must be committed, which clutters history.

GitHub Actions. A workflow builds the site and hands the result to Pages. You choose a suggested workflow template or write your own. This is the better choice once there is a build step, and it keeps generated files out of the repo.

I read this in GitHub’s “Configuring a publishing source” page on 2026-11-23. I could not click through it, because I have no GitHub account where I wrote this lesson.

A workflow for the notes site

The notes project has a build script that writes dist/index.html. I ran npm test and npm run build locally, and both worked, producing dist/index.html. This workflow runs the same two commands and publishes dist:

name: Deploy site

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: false

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm test
      - run: npm run build
      - uses: actions/configure-pages@v6
      - uses: actions/upload-pages-artifact@v5
        with:
          path: dist

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - id: deployment
        uses: actions/deploy-pages@v5

I loaded this with a YAML parser, so the syntax is valid. I could not run it, since it needs a real repository with Pages enabled. Here is what each part does.

  • permissions. The deploy needs pages: write and id-token: write, which the docs state. contents: read is for the checkout.
  • concurrency. Only one Pages deployment should run at a time, and cancel-in-progress: false lets a running deploy finish instead of being cut off.
  • needs: build. The deploy job waits for the build job. Without it, the jobs start together and the deploy can look for an artifact that is not there yet.
  • environment: github-pages. The deploy job runs in the github-pages environment, which GitHub creates if it is missing. The docs recommend adding a rule limiting deployments to the default branch. The url is the page address, taken from the deploy step’s page_url output, which I confirmed in that action’s action.yml.
  • workflow_dispatch. It adds a manual “Run workflow” button.

Versions, checked against the real releases

The action tags above were the latest releases when I checked on 2026-11-23: actions/checkout v7.0.1, actions/setup-node v7.1.0, actions/configure-pages v6.0.0, actions/upload-pages-artifact v5.0.0 and actions/deploy-pages v5.0.1. The major tags (v7, v6, v5) all exist. I also read each action.yml at those tags.

One finding: GitHub’s own Pages docs page lags the releases. Its example workflow still shows checkout@v6, configure-pages@v5, upload-pages-artifact@v4 and deploy-pages@v4. Those older versions presumably still work, but copying docs examples means copying old pins. Dependabot, covered in the next lesson, can keep these current.

Things that catch people out

  • Hidden files are not published. upload-pages-artifact has include-hidden-files, default false, and the action’s own description says it excludes .git and .github always. So a dist/.well-known/ folder will be missing from the live site unless you turn that on.
  • A CNAME file does not set a custom domain. The docs say you must configure the domain in the repository settings or through the API.
  • Everything is public. The published files are served on the web. Do not publish .env files, internal docs or build logs by mistake. Publish the dist folder, not the repository root.
  • It is static only. There are no server-side scripts, databases or logins. You can call external APIs from browser JavaScript, but anything with a secret in it must run elsewhere.

Limits and rules

From GitHub’s “Pages limits” page, read on 2026-11-23:

  • One user or organization site per account. (Per-repository project sites are a separate thing, and I did not check their limits.)
  • Published sites may be at most 1 GB, and the source repository should stay under 1 GB.
  • Deployments time out after 10 minutes.
  • A soft bandwidth limit of 100 GB per month, and a soft limit of 10 builds per hour that does not apply when you deploy with a custom Actions workflow.
  • Not for running an online business, e-commerce or SaaS, and not for sensitive transactions.

I did not confirm from the docs which plans allow Pages on private repositories, so check the current plan table.

What the video covers

Corey Schafer’s “How to Deploy a Static Website to GitHub Pages - Free Hosting Tutorial” runs about 24 minutes and was published around 2025. The description says it shows how to deploy a static site to GitHub Pages as a simple, free way to host a portfolio. I could not read a transcript or chapters, so I cannot say whether it uses the branch source or the Actions source. Videos on this topic often use the branch option, which is the older, simpler route. It is likely to match the first half of this page rather than the workflow. English is judged from the title, description and the channel’s reputation. A newer 2026 video by Coder Coder was my first choice, but its embedding is disabled, so the link check dropped it.

Where this fits

Pages shows a repository doing something on its own after a push. The next lesson covers a quieter helper: keeping your dependencies updated. Dependabot and dependency updates.

Check yourself

  1. 01What is the difference between Deploy from a branch and the GitHub Actions source?

    From a branch, GitHub serves files already committed on a branch and folder as they are. With Actions, a workflow builds the site and uploads an artifact, so you can run a build step and keep generated files out of your repository.

  2. 02Why does the deploy job need needs: build?

    Without it the two jobs run in parallel and the deploy job can look for an artifact that does not exist yet. needs makes it wait for the build job to finish and upload.

  3. 03Can you run a login system or payment flow on GitHub Pages?

    No. Pages is static hosting. Its terms also forbid using it as free hosting for a commercial service or for handling sensitive transactions such as passwords or card numbers.

  4. 04You put a .well-known folder in dist but it is missing from the live site. Why?

    The upload-pages-artifact action leaves out hidden files and folders, those starting with a dot, unless you set include-hidden-files to true. It always excludes .git and .github.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark