In this short tutorial, we will be going step-by-step through the process of how to use a custom domain you've purchased (like mywebsite.com) for a site you are hosting on Github Pages.
Assuming you have already purchased a domain through a registrar like GoDaddy or Namecheap, all you have to do is add a couple key pieces of information both in your account with the registrar and Github.
So, for example, if you used Namecheap to purchase your domain, you’d login to your account there and look for Advanced DNS after clicking on the domain you want to host with Github Pages.
Once you’re there, you will need to add two different types of DNS records.
First, you will need to create four A records pointing to Github’s servers.
Host | Value |
@ | 185.199.108.153 |
@ | 185.199.109.153 |
@ | 185.199.110.153 |
@ | 185.199.111.153 |
+Add new record —> A record —> Host: @ Value: 185.199.108.153
Host | Value |
www |
The other type of DNS record you need to add is a CNAME Record.
+Add new record —> CNAME record —> Host: www Value: username.github.io
These records tell your domain where your website actually lives (in this case, GitHub’s servers).
By adding both these types of DNS records, you ensure that both yourdomain.com and www.yourdomain.com direct visitors to your actual website on Github Pages.
GitHub supports two types of sites:
A special username.github.io repo (your main site)
Or any individual repo (project sites like this one)
Next, head over to your Github repo you want to connect to your custom domain. You can use any repository for this. GitHub will serve your site from whichever repo you connect your domain to.
Go to the repo Settings tab on the far right.
Along the left sidebar, choose Pages.
In the text field for Custom Domain, enter yourdomain.com (replace this with your actual domain). Behind the scenes, GitHub creates a
CNAMEfile.Check the box next to Enforce HTTPS.
Make sure Source is set to Deploy from a branch
For Branch, select main
Save settings
Now all you have to do is wait for the DNS records to update, which can take up to 24 hours.
Once that happens, everything should be correctly synced up.
To test it, try visiting your domain by typing it into a browser and if it takes you to the site you created on Github, then you are all set. You can use the Github repo as your CMS going forward.
If it doesn’t work right away:
DNS changes can take up to 24 hours
Try clearing your browser cache or checking in an incognito window