How to Add a Custom Domain to your Github Pages Website


by Thomas Tran



If you are anything like me, then you’ve had to link a custom domain to your Github Pages site. But, if you are me reading this in the future, then you’ll know that I do this so rarely that I forget how to do it every time, which always ends up with me spending valuable time researching this for the nth time. Combined with the long-term nature of DNS propagation and the fact that I won’t get to see if what I did worked for up to 24 hours, I often get stressed when it doesn’t work out the way it should!

This article serves as a guide for future me and other people on how to connect a custom domain to your Github Pages website.

Steps

  1. Register a domain name with your favorite registrar. Some fan favorites include GoDaddy, 1&1 IONOS, and Google Domain. If you’re on a tight budget and can’t afford a domain, or if you’re just learning, then you can use FreeNom to get a free domain name. This is what I did for this website!

  2. Go to the Settings tab of your repo. Under the Custom Domain option, input your domain name and hit Save. Your <repo>.github.io domain will now redirect to your custom domain.

  1. Now we need to update the DNS settings to point to Github Pages. Otherwise when you go directly to your custom domain, it won’t point to your <repo>.github.io page.

  2. In your DNS settings, create a CNAME record that points to your <repo>.github.io address.

  1. Now let’s create some A records so that we can have our apex domain be thomastran.ml instead of www.thomastran.ml:
  1. If you want your website to enforce HTTPS encryption, select Enforce HTTPS in your settings. It can take up to 24 hours before this option is available.

  2. Add a CNAME file to the root of your Github repo. The content of the file should be the name of your domain. My CNAME is the following:

thomastran.ml
  1. And remember, it takes DNS propagation up to 24 hours to complete, so you may have to wait for your changes to reflect!