Sub topic 12
Troubleshooting failed builds, 404s, and broken styles
This chapter assumes you can publish a site from a branch or a GitHub Actions workflow. It also assumes you know the difference between user, organization, and project site URLs. Most Pages problems fall into three groups: the deployment failed, the site returns a 404, or the page loads without its styles. Work out which group you are in first, because each one points to a different place to look.
Find which stage failed
A deployment passes through a few stages. Checking them in order saves time.
Failed builds and deployments
Open the Actions tab of the repository and select the failed run. Expand the step with the red mark and read the first error, not the last one. Later errors are often side effects of the first.
Common causes with a custom workflow:
- Missing permissions. The deploy action needs
pages: writeandid-token: write. If thepermissionsblock is missing, the deploy step fails with an authorization error. - Wrong artifact path. If
path: sitepoints to a folder that does not exist, the upload step fails or uploads nothing. Check that the folder name matches your repository. - Wrong publishing source. A workflow only deploys if the Pages source in Settings > Pages is set to GitHub Actions. If it is still set to a branch, the workflow runs but the site does not update.
- Environment protection. The
github-pagesenvironment can have branch rules. A push from a branch the environment does not allow is rejected.
With branch publishing, GitHub runs its own build, and Jekyll can fail on a Markdown or Liquid error. The message appears in the run for the pages build and deployment workflow. A stray {{ or {% in a file is a typical trigger. If you do not need Jekyll, add an empty .nojekyll file at the published root:
touch .nojekyll
git add .nojekyll
git commit -m "Disable Jekyll processing"
git push404 responses
A 404 means the server has no file for the URL you asked for. Check these in order:
- Source setting. In Settings > Pages, confirm the branch and folder (
/or/docs) match where your files actually are. - Entry file. The published root needs
index.html. The name is case-sensitive, soIndex.htmlfails. - Case in other files. Your laptop may ignore case, but the Pages server does not.
Style.cssandstyle.cssare different files. - Deployment finished. A new site can take a few minutes. Look for a green run before assuming something is broken.
- Project path. A project site lives at
https://USERNAME.github.io/REPO/. Openinghttps://USERNAME.github.io/page.htmlgives a 404 even when the file exists.
Broken styles
If the HTML appears but looks unstyled, open the browser developer tools and look at the Network tab. A stylesheet request with a 404 status shows the exact URL the browser tried.
The usual cause is a root-relative path on a project site. This link starts at the domain root, so it loses the repository name:
<link rel="stylesheet" href="/style.css">On a project site, the browser requests https://USERNAME.github.io/style.css, which does not exist. Use a path relative to the page instead:
<link rel="stylesheet" href="style.css">For pages in subfolders, use ../style.css, or include the repository name, as in /REPO/style.css.
Other causes are a mixed-content block (an http:// stylesheet on an HTTPS page) and a custom domain whose DNS has not finished propagating.
Quick reference
| Symptom | First thing to check |
|---|---|
| Red X in Actions | The first error in the failed step |
| Workflow green, site unchanged | Pages source set to GitHub Actions |
| 404 on the home page | `index.html` at the published root |
| 404 only on some files | File name case and folder |
| Unstyled page | Stylesheet URL in the Network tab |
Exercise
Your project site at https://USERNAME.github.io/notes/ loads, but the styles are missing. The HTML contains <link rel="stylesheet" href="/css/main.css">. What is wrong, and how do you fix it?
Show answer
The path starts with /, so the browser requests https://USERNAME.github.io/css/main.css and leaves out the /notes/ project path, which returns a 404. Change it to the relative path css/main.css (or /notes/css/main.css).
Exercise
Your workflow run is green, but the live site still shows old content. Which setting do you check first?
Show answer
Open Settings > Pages and confirm the source is set to GitHub Actions. If it is set to a branch, the workflow does not control what is published.