GitHub Pages is GitHub’s free web hosting. It serves the finished site; the deployment action in the next guide builds it and hands it over.
Switch it on
- Open your repo on GitHub and click Settings.
- In the sidebar, under Code and automation, click Pages.
- Under Build and deployment, set Source to GitHub Actions.
That’s the only required setting. GitHub may offer a ready-made Hugo workflow at this point. You can skip it: the next guide gives you one that pins the same Hugo version you installed, so the site builds the same way on GitHub as on your computer.
Your site’s address
| Repo name | Site address |
|---|---|
janedoe.github.io | https://janedoe.github.io/ |
anything else, e.g. myblog | https://janedoe.github.io/myblog/ |
Put that address in hugo.toml as the baseURL:
baseURL = 'https://janedoe.github.io/myblog/'
The deployment action sets the address automatically when it builds, but keeping baseURL correct means feeds and links are right everywhere else too.
Use your own domain (optional)
If you own a domain, GitHub Pages can serve the site there, with a free HTTPS certificate.
Verify the domain first, so nobody else can attach it to their Pages site. Click your profile picture, then Settings → Pages → Add a domain, and add the TXT record GitHub shows you at your domain registrar.
Add DNS records at your registrar. For
www.example.com, add aCNAMErecord forwwwpointing tojanedoe.github.io. For the bareexample.com, add these:Type Name Value A @ 185.199.108.153A @ 185.199.109.153A @ 185.199.110.153A @ 185.199.111.153AAAA @ 2606:50c0:8000::153AAAA @ 2606:50c0:8001::153AAAA @ 2606:50c0:8002::153AAAA @ 2606:50c0:8003::153Set up both and GitHub redirects one to the other.
Tell GitHub. In the repo’s Settings → Pages, type the domain under Custom domain and click Save. GitHub checks the DNS; this can take from a few minutes to a day while the records spread.
Turn on HTTPS. Once the check passes, tick Enforce HTTPS. The certificate can take a little while to issue; the checkbox stays grey until it’s ready.
Update
baseURLinhugo.tomlto the new address, such ashttps://www.example.com/.
Because the site deploys with an action, you don’t need a CNAME file in the repo. The setting in step 3 is what counts.