Before you start
- A free GitHub account. Sign up at github.com.
- A domain name from any registrar, such as Domains.co.za, Afrihost, Namecheap, GoDaddy or Cloudflare.
- Access to your domain’s DNS settings, usually called “DNS management” or “Manage DNS” in your registrar’s dashboard.
- About 30 minutes, plus waiting time while DNS updates.
Throughout this guide, replace USERNAME with your GitHub username and yourdomain.com with your real domain.
The 6 steps
Publish your site with GitHub Pages
Create a new repository and upload your website files, with your home page named
index.html. Then open the repository’s Settings → Pages. Under Build and deployment, set Source to Deploy from a branch, choosemainand/ (root), and click Save.After a minute or two your site is live at
https://USERNAME.github.io/REPOSITORY/. Open it to make sure it works before you continue.Verify your domain with GitHub
This step proves you own the domain, so nobody else can ever publish a GitHub Pages site on it. Do it before you change any DNS records.
Click your profile picture → Settings (your account settings, not the repository’s) → Pages → Add a domain. Type
yourdomain.comand GitHub shows you a TXT record like this:Type Host / Name Value TXT_github-pages-challenge-USERNAMEThe code GitHub shows you Add that record at your DNS provider, wait a few minutes, then click Verify. Keep this TXT record in place permanently.
Add the custom domain to your repository
Go back to the repository’s Settings → Pages. Under Custom domain, type
www.yourdomain.comand click Save.When you publish from a branch, GitHub adds a file called
CNAMEto your repository holding your domain. Leave it there. If you publish with a GitHub Actions workflow instead, no CNAME file is needed.Create the DNS records
At your DNS provider, delete any old “parking” A or CNAME records for
@andwww, then add these:Type Host / Name Points to / Value Purpose CNAMEwwwUSERNAME.github.ioYour main address A@185.199.108.153The bare domain, which GitHub redirects to www A@185.199.109.153A@185.199.110.153A@185.199.111.153All four A records at once:
185.199.108.153 185.199.109.153 185.199.110.153 185.199.111.153
Optional, for IPv6: add four AAAA records for
@:2606:50c0:8000::153 2606:50c0:8001::153 2606:50c0:8002::153 2606:50c0:8003::153
Tips. The CNAME value is only your username plus
.github.io, without the repository name. Some providers call@the “root” or leave the name blank. Don’t create a wildcard record like*.yourdomain.com. On Cloudflare, set these records to DNS only (grey cloud) until HTTPS is working.Check that DNS has updated
DNS changes usually show up within minutes, but can take up to 24 hours. On Mac or Linux, run:
dig www.yourdomain.com +nostats +nocomments +nocmd dig yourdomain.com +noall +answer -t A
The first should show a CNAME to
USERNAME.github.io. The second should list the four185.199.x.153addresses. On Windows or your phone, an online tool such as a DNS checker website works too. Back in Settings → Pages, GitHub shows “DNS check successful” when it’s right.Turn on Enforce HTTPS
Once DNS is correct, GitHub issues a free security certificate. This usually takes a few minutes to an hour. When the Enforce HTTPS box becomes available in Settings → Pages, tick it. Your site now loads securely at
https://www.yourdomain.com, and visitors who type the bare domain are redirected automatically.
Troubleshooting
| Problem | Fix |
|---|---|
| “Domain’s DNS record could not be retrieved” or “improperly configured” | Check the records in step 4 for typos, delete old parking records, and wait. DNS can take up to 24 hours. |
| Enforce HTTPS is greyed out | Wait up to an hour after DNS is correct. If it stays greyed out, remove the custom domain, save, then add it again. If you use CAA records, one must allow letsencrypt.org. |
| “Domain is already taken” | Complete the verification in step 2. That claims the domain for your account. |
| Custom domain disappears after you upload files | Your upload deleted the CNAME file. Re-add the domain in Settings, or keep a file named CNAME (all capitals) containing only www.yourdomain.com. |
| Site shows a 404 page | Make sure your home page is named index.html and sits in the folder you chose in step 1. |
| Old version still showing | Clear your browser cache or open the site in a private window. |
Common questions
How much does GitHub Pages hosting cost?
Hosting a public website on GitHub Pages is free. You only pay your registrar for the domain name itself, usually once a year.
Should I use www or the bare domain?
Use www.yourdomain.com as the main address and set up both. GitHub then redirects the bare domain (yourdomain.com) to www automatically, and www works better with DNS providers and CDNs.
How long does it take to go live?
Usually minutes to a few hours. DNS changes can take up to 24 hours to spread, and the HTTPS certificate can take up to an hour after DNS is correct.
Why is Enforce HTTPS greyed out?
GitHub has not issued the certificate yet. Check your DNS records are correct, wait up to an hour, and if it stays greyed out, remove the custom domain in Settings, save, then add it again.
Need a hand?
This guide follows GitHub’s official documentation on managing a custom domain and verifying your domain. If you get stuck, message me and tell me which step you’re on.