Sub topic 4
Choosing a publishing source
This chapter assumes you can use Git (clone, commit, push, branches), have a GitHub repository with a basic HTML page, and can read a YAML file. You will learn the two ways GitHub Pages can publish your files and how to pick between them.
What a publishing source is
A publishing source tells GitHub Pages where the files to serve come from. You choose it in the repository under Settings, then Pages, in the Build and deployment section. There are two choices:
- Deploy from a branch. GitHub publishes the files in a branch and folder you name.
- GitHub Actions. A workflow in your repository builds or collects the files and deploys them.
Only one source is active at a time. Switching changes what the next deployment uses. It does not delete your files.
Branch publishing
With this source, you pick a branch and a folder. The folder is either the repository root (/) or /docs. Every push to that branch triggers a new deployment.
The files in that folder are the site. For a first deployment, an index.html at the publishing root is enough:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My site</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Hello from GitHub Pages</h1>
</body>
</html>The relative stylesheet link keeps working when the site is served from a project path.
Branch publishing has few moving parts, but it has two limits:
- You can only publish the root or
/docs. A folder with another name, such assite, is not allowed. - The files in the folder must already be the finished site, unless you use Jekyll, which GitHub runs for you on this source.
Publishing with a GitHub Actions workflow
With this source, GitHub does not look at a branch folder. Your workflow uploads an artifact (a packaged copy of the site files) and a deploy step publishes it. This workflow publishes a folder named site:
name: Deploy static site to Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: site
- id: deployment
uses: actions/deploy-pages@v4Several parts are required for the deploy to work:
permissionsgives the workflow's token the rights to write to Pages and to request an identity token (id-token: write) that proves the deployment is legitimate.environment: github-pageslinks the job to the Pages deployment environment. Theurlline shows the live address on the run summary.concurrencywithcancel-in-progress: falselets a running deployment finish instead of being cancelled by a newer push.path: siteis the folder to publish. Change it to match your layout.
Comparing the two sources
| Question | Branch | GitHub Actions |
|---|---|---|
| Where do site files live? | Root or `/docs` of one branch | Any folder, or build output |
| Setup effort | Select a branch and folder | Write and maintain a workflow file |
| Build step | Jekyll only | Any tool you can run in a job |
| Where to see failures | Pages settings and the deployment list | Actions run logs |
How to decide
In short:
- Choose a branch when you hand-write HTML, or use Jekyll, and the files already sit in the root or
/docs. - Choose Actions when a tool generates the site, when the finished files live in a folder with another name, or when you want the build to be explicit and repeatable.
Common errors
- The site does not change after a push. Check that the source matches how you publish. A branch source ignores your workflow, and an Actions source ignores the branch folder.
- The deploy job fails with a permissions error. Confirm that
pages: writeandid-token: writeare present in the workflow. - You cannot select the folder you want. Branch publishing offers only
/and/docs. Move the files, or switch to Actions.
Exercise
Your build tool writes the finished site to a folder named dist on the main branch. Which publishing source do you choose, and which line in the workflow tells it what to publish?
Show answer
Choose GitHub Actions, because branch publishing can only serve / or /docs. In the actions/upload-pages-artifact step, set path: dist.
Exercise
A workflow run succeeds, but the live site still shows old content. The Pages source is set to "Deploy from a branch". What is the likely cause and fix?
Show answer
The source is not set to GitHub Actions, so the workflow's artifact is not what gets served. In Settings, then Pages, change the source to GitHub Actions and run the workflow again.