Introduction

When you publish a site with GitHub Pages, the default address will look something like this: https://<username>.github.io/<repo name>. For example, https://intodeeplearning.github.io/blog.

If you’d like to replace the default address with your custom domain, such as https://intodeeplearning.com , follow this tutorial!

What you will get in this tutorial

  • Setting up a custom www subdomain, such as www.example.com, for your GitHub Pages
  • having the apex domain, such as example.com, automatically redirect to www.example.com

What you need



Step 1. Setup in your Github Repo

  • Go to Settings > Pages > Custom domain, and add you custom domain name, such as “www.intodeeplearning.com”

    example image

Step 2. (Optional) You can skip this step if you are NOT using a site generator, such as fastpages, or Jekyll

If you are using fastpages.

Step 3. Let your custom domain point to your GitHub Pages

  • Go to your google domain registrar and select your domain.

  • Go to the DNS tab

    example image

  • Under the Resource records section, click Manage custom records

    example image

  • Create a CNAME record that points your www subdomain to <your_github_username>.github.io

    example image

    • Do NOT include the repository name, such as intodeeplearning.github.io/blog. If you include your repository name in the CNAME record to your DNS provider, you’ll get the below message at your GitHub Settings > Pages > Custom domain

      example image

  • Create an A record that points to the IP addresses for Github Pages.

    example image

    • IP addresses in the screenshot

        185.199.108.153
        185.199.109.153
        185.199.110.153
        185.199.111.153
      
    • Check here if there’s an update in the IP addresses.

  • Open Terminal to confirm that your DNS record configured correctly

    • For CNAME records, do

        dig www.intodeeplearning.com +nostats +nocomments +nocmd
      
      • You should get

          ; <<>> DiG 9.10.6 <<>> www.intodeeplearning.com +nostats +nocomments +nocmd
          ;; global options: +cmd
          ;www.intodeeplearning.com.	IN	A
          www.intodeeplearning.com. 3312	IN	CNAME	intodeeplearning.github.io.
          intodeeplearning.github.io. 3312 IN	A	185.199.110.153
          intodeeplearning.github.io. 3312 IN	A	185.199.111.153
          intodeeplearning.github.io. 3312 IN	A	185.199.109.153
          intodeeplearning.github.io. 3312 IN	A	185.199.108.153
        
    • For A records, do

        dig intodeeplearning.com +noall +answer -t A
      
      • You should get

         ;; global options: +cmd
         intodeeplearning.com.	928	IN	A	185.199.109.153
         intodeeplearning.com.	928	IN	A	185.199.108.153
         intodeeplearning.com.	928	IN	A	185.199.110.153
         intodeeplearning.com.	928	IN	A	185.199.111.153
        

Step 4. Enable HTTPS for you GitHub Pages

  • Go to your github repository settings page, under Settings > Pages, remove your custom domain and save.

  • Then add it back and save again.

  • Now you should be able to check the Enforce HTTPS checkbox

    example image

  • Note: DNS changes can take up to 24 hours to propagate.



That’s it! Your website should be publishing at your custom domain now!

Reference