Custom domains
Introduction
GitHub Pages static hosting: custom domains, DNS records, and deployment workflows.
- GitHub Pages documentation (docs.github.com)
- Managing a custom domain (docs.github.com)
- Configuring a publishing source (docs.github.com)
Enable the domain
echo "example.com" > CNAME
Enter the domain under Settings → Pages → Custom domain. Saving commits this CNAME file when you publish from a branch; a Pages workflow ignores it.
Point DNS at GitHub
| Type | Host | Value |
|---|---|---|
CNAME | www | <user>.github.io |
ALIAS | @ | <user>.github.io |
A | @ | 185.199.108.153 |
A | @ | 185.199.109.153 |
A | @ | 185.199.110.153 |
A | @ | 185.199.111.153 |
AAAA | @ | 2606:50c0:8000::153 |
AAAA | @ | 2606:50c0:8001::153 |
AAAA | @ | 2606:50c0:8002::153 |
AAAA | @ | 2606:50c0:8003::153 |
Use ALIAS or the A records for an apex domain, not both. The CNAME target takes no repository name.
Check the setup
Records
dig example.com +noall +answer -t A
HTTPS
curl -sI http://example.com | head -1
Tick Enforce HTTPS once GitHub issues the certificate, which can take 24 hours after DNS resolves.
Deploy
From a branch
Under Settings → Pages, set Source to Deploy from a branch and pick the branch and folder (/ or /docs). Jekyll builds on every push.
With a workflow
on:
push:
branches: [main]
permissions:
contents: read
pages: write
id-token: write
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v4
with:
path: _site
- id: deployment
uses: actions/deploy-pages@v4
Set Source to GitHub Actions first, and build _site before the upload step. The job needs pages: write and id-token: write.
0 Comments for this cheatsheet. Write yours!