How to Connect Your Own Domain to GitHub Pages
A practical walkthrough for pointing a domain you own at a GitHub Pages site, covering apex and www setups, DNS records, verification and common mistakes.
10 min readUpdated Nov 27, 2026By XPASS Editorial Team

Putting a site on GitHub Pages gives you an address such as username.github.io. That is fine for a test, but a business, portfolio or project page usually looks better and is easier to remember on a domain you own. Connecting the two is not difficult, yet it involves three separate places that must agree with each other: the DNS records at your domain provider, the Pages settings in your repository, and the HTTPS certificate that GitHub issues for the name. Most failed setups come from one of the three being out of step with the others.
This guide walks through the whole process in the order that causes the fewest surprises. You will decide between an apex domain and a www address, add the DNS records, set the custom domain in the repository, verify it, and turn on HTTPS. If you want a general refresher on what each record does first, the background on how DNS answers questions about a name is a useful companion read. The steps below use plain examples and do not assume you have done this before.
What you need before you start
Gather a few things first, because switching between tabs while DNS is half changed is how mistakes happen.
- A GitHub repository with a working Pages site. Open the normal github.io address and confirm that the page loads. If the default address is broken, a custom domain will not fix it.
- A domain you control, and access to its DNS settings. This might be at the registrar where you bought it or at a separate DNS host if you moved the nameservers. If you do not own a domain yet, you can look at the options on the domains page.
- A decision about which address visitors should see: the bare name such as example.com (called the apex or root domain), or the www version such as www.example.com.
- A note of anything already attached to the domain, such as business email. Email depends on MX and TXT records, and you must not delete them while editing website records.
Take a screenshot or copy the existing DNS records into a text file before you change anything. If something goes wrong, you can restore the earlier state quickly.

Choose apex, www, or both
GitHub Pages supports three common patterns, and your choice affects which DNS records you add.
| Pattern | Example | DNS record type | Notes |
|---|---|---|---|
| Apex domain | example.com | A (and optionally AAAA) | Several records pointing at GitHub |
| www subdomain | www.example.com | CNAME | Points at your GitHub user or organization address |
| Other subdomain | blog.example.com | CNAME | Same method as www |
The most robust setup is to configure both the apex and www. You set one of them as the custom domain in the repository, and GitHub automatically redirects the other to it. Visitors who type either form arrive at the same site, and search engines see one consistent address.
If you prefer to keep things minimal, a single subdomain such as docs.example.com is the simplest case. It needs one CNAME record and nothing else. An apex-only setup is also valid, but you then rely on the A records, and a CNAME at the apex is generally not allowed by the DNS rules at most providers because the apex already carries other required records. Some providers offer a special alias or flattening feature for this, but it is not necessary for GitHub Pages.
Add the DNS records
Log in to the place where your domain's DNS is managed and open the DNS records screen. The labels differ between providers, but the fields are always the same: type, name (or host), value (or target) and TTL.
Records for an apex domain
For example.com, add A records for the apex name, usually shown as an at sign or left blank. GitHub documents four IPv4 addresses for Pages:
- 185.199.108.153
- 185.199.109.153
- 185.199.110.153
- 185.199.111.153
If you want the site reachable over IPv6 too, GitHub also documents four AAAA addresses beginning 2606:50c0:8000::153 and continuing with 8001, 8002 and 8003 in the fourth group. Always check the current GitHub documentation before copying addresses, because infrastructure details can change and your provider's help pages are not a substitute for the official list.
Remove any older A or AAAA records for the apex that point to a previous host, such as a parking page. Mixed answers send some visitors to the old server and some to GitHub, which looks like random breakage.
Record for www or another subdomain
Add a CNAME record. The name is www (or blog, docs and so on), and the value is your GitHub address, for example username.github.io. Do not include the repository name in the CNAME target, and do not add a trailing path. For an organization, use the organization's github.io address instead.
A CNAME must be the only record for its name. If a www entry already exists as an A record or a different CNAME, delete or edit it instead of adding a second one.
Leave other records alone
Records for email, such as MX, SPF, DKIM and DMARC, are separate from website records and must stay as they are. The same is true for any TXT records used to verify ownership with other services. If you use a company mailbox, the business email page explains what that service adds to your DNS, so you can recognise which records belong to it.
Set the custom domain in the repository
With DNS in place, tell GitHub which name this site answers to.
- Open the repository on GitHub and go to Settings, then Pages.
- Under the custom domain field, type your chosen address exactly, for example www.example.com or example.com, and save.
- GitHub runs a DNS check. A green message means the records are correct; an error message normally names the problem, such as a missing record or one that points elsewhere.
When your site is published from a branch, saving the setting creates a file named CNAME at the root of the published branch, containing your domain on a single line. Do not delete it. If you ever rebuild the site and your build output wipes that file, the custom domain setting will disappear after the next deploy, which is a common surprise with static site generators. In that case, put a CNAME file in the folder that is copied to the output, such as a public or static directory.
When your site is published by a GitHub Actions workflow, the CNAME file is not used, but you should still set the custom domain in the settings so GitHub knows to serve it.
Verify the domain to protect it from takeover
GitHub lets account owners verify domains for Pages. Verification adds a TXT record that proves you control the name, and it prevents someone else from claiming your domain in their own Pages site if your DNS ever points at GitHub with nothing behind it.
The process is short. In your account or organization settings, open the Pages section, choose to add a domain, and enter it. GitHub shows a TXT record name and value. Add that record at your DNS provider, wait for it to propagate, and press the verify button. The record can stay in place afterwards. Verification is optional for a basic site, but it is a sensible habit for any domain you care about, and it protects against dangling DNS entries if you later stop using the repository.
Turn on HTTPS
Once GitHub sees correct DNS records, it requests a certificate for your name automatically, using the same automated certificate model described in how Let's Encrypt issues certificates. This can take from a few minutes to about an hour. When the certificate is ready, the Enforce HTTPS checkbox in the Pages settings becomes available. Tick it so that visitors on plain HTTP are redirected to the secure address.
If the checkbox stays greyed out, work through this checklist:
- The DNS records are not yet visible everywhere. Wait and test again.
- A leftover AAAA record, or an old A record, still points at another server.
- A CAA record at your domain disallows the certificate authority that GitHub uses. If your domain has CAA records, make sure they permit the issuer, or remove the restrictive record.
- The custom domain was changed recently. Remove it, save, add it again, and wait.
Everything the browser shows after that, including the padlock, relies on that certificate. If you later need a certificate for something beyond GitHub Pages, such as a separate server or an API, the SSL certificates page describes the options at a high level.
A worked example
Imagine you own example.org and want the project page to live at www.example.org, with the bare name redirecting to it.
- In the repository settings, you set the custom domain to www.example.org.
- At the DNS provider you add a CNAME for www with the value myname.github.io.
- You add the four A records for the apex pointing to the four GitHub addresses, and delete the old parking page record.
- You wait several minutes and open Settings, Pages again. The DNS check shows success.
- You tick Enforce HTTPS once it becomes available.
- You test four addresses in a private browser window: http and https for example.org and for www.example.org. All four should end at the same https address of www.example.org.
If one of the four tests ends somewhere unexpected, the result tells you where to look. A failure only on the bare name usually means the apex A records are wrong. A failure only on www means the CNAME is wrong.

Limits and things to watch for
GitHub Pages is a static hosting service, so a few boundaries are worth knowing before you build a business around it.
- Pages serves static files. It does not run server-side code, databases or form handlers. Use a separate service for those.
- There are published usage limits on site size and monthly bandwidth, and the service is not intended for running an online store or high-volume commercial transactions. Read the current GitHub terms and limits for your account type.
- Only one custom domain is configured per Pages site, although you can redirect other names to it through the apex and www pair.
- Wildcard DNS records are discouraged for Pages, because they increase the chance of someone else pointing a subdomain at your account.
- Changing DNS takes time. The previous TTL controls how long other networks may remember the old answer. Lowering the TTL a day before a planned change makes the switch faster.
- Private repositories can publish Pages only on certain account plans. Check what your plan supports.
Treat the domain itself as an asset that needs care: keep the registration renewed, keep the contact details current, and do not leave records pointing at services you no longer use.
Troubleshooting common errors
| Symptom | Likely cause | What to do |
|---|---|---|
| Domain shows a 404 page from GitHub | Custom domain set in DNS but not in repository settings, or the build output is missing | Set the domain in Pages settings and confirm the site builds |
| Certificate warning in the browser | Certificate not issued yet, or wrong records | Wait, then recheck the DNS records and the HTTPS setting |
| Works at www but not at the bare name | Missing or wrong apex A records | Add all four A records and remove old ones |
| Old site still appears | DNS cache or a leftover record | Wait for the TTL, flush local cache, remove stale records |
| Domain disappears after each deploy | CNAME file overwritten by the build | Keep the file in the static folder that is copied to the output |
| Email stopped working | MX records were deleted by mistake | Restore the saved copy of the email records |
When you test, use a private browser window and a different network, such as a phone on mobile data. Your own computer and router cache DNS answers, so you may see old results long after the world has moved on. The way names are resolved is set out in the original DNS concepts specification, which explains why caching and delegation behave this way.
Related guides
If you publish more than one site, the same pattern applies to other platforms with small differences. The steps for connecting a domain to Notion Sites show how a managed page builder handles it, connecting a domain to Ghost covers a publishing platform, and connecting a domain to Astro is helpful if your GitHub Pages site is built with that framework.
Summary
Connecting your own domain to GitHub Pages comes down to four actions in the right order. Choose apex, www or both. Add the matching A and CNAME records at your DNS provider and leave email records untouched. Set the custom domain in the repository, and verify it if you want extra protection. Then wait for the certificate and enforce HTTPS. Test from a clean browser and a different network, and keep a copy of your old records in case you need to roll back. If you still need a name for the site, the domains page is a good place to start.
Frequently asked questions
Do I need both an apex domain and a www record for GitHub Pages?
No, but it is the most reliable setup. You choose one as the primary address in the repository settings, and GitHub redirects the other one to it when both are configured correctly.
Why does the HTTPS checkbox stay greyed out?
Usually the DNS records have not propagated yet, or they still point somewhere else. Wait for DNS to update, confirm the records, and GitHub will then issue the certificate so you can enforce HTTPS.
Should I add a CNAME file to the repository?
When you publish from a branch, setting the custom domain in the Pages settings creates the CNAME file for you. If you publish with a GitHub Actions workflow, the file is not needed, but the domain must still be set in the settings.
Can I keep my business email working while I change the website records?
Yes, as long as you only edit the web records (A, AAAA and CNAME for the website) and leave MX, SPF, DKIM and DMARC records untouched.
How long does a domain take to start working with GitHub Pages?
Often a few minutes, but DNS caches can keep old answers for up to the TTL of the previous record. Allow some hours before you assume something is broken.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Start your website the right way
Register a domain, add SSL and set up business email from one place.
.com registration from $18.81 for the first year
Start with a domainKeep reading

Website Guides
How to Connect a Custom Domain to Notion Sites
Turn a published Notion page into a site on your own address. Learn which DNS record to add, how verification works and what to check afterwards.
9 min read

Website Guides
How to Connect a Custom Domain to Ghost
A practical walkthrough for pointing your own domain at a Ghost publication, with DNS records, redirects, email safety and a checklist of common mistakes.
10 min read

Website Guides
How to Connect Your Own Domain to an Astro Site
A practical guide to connecting a custom domain to an Astro project, covering static and server builds, DNS records, the site setting and common problems.
10 min read