DEV Community

Trent Yang
Trent Yang

Posted on • Edited on

How to setup google domain for github pages

google domains and github pages

Intro

Github pages is easy to setup, but to attach a custom domain with google domains, you may run into problems. Here is how you can do it in 4 steps.

Prerequisites

STEP 1/4: Let gitHub pages know your custom domain

  • Go to your github repository settings page
    GitHub Settings

  • Add you custom domain name at Settings > GitHub Pages > Custom domain
    GitHub Settings Github Pages

STEP 2/4: Let your custom domain (trentyang.com) points to your github pages

  • Go to registar page on your google domains, select your domain
    Google Domain Register

  • Go to DNS > Custom resource records
    DNS Custom resource records

  • Add the record shown in the screenshot bellow. Note that you need to use the "+" button to add more urls.
    A record
    Here is the list of ips in the screenshot:

    • 185.199.111.153
    • 185.199.110.153
    • 185.199.109.153
    • 185.199.108.153

Incase these are outdated, you can also find the latest ones at github.

  • To confirm that your DNS record is set up correctly, use the dig command to do a lookup of your domain ```console

$ dig trentyang.com +noall +answer
trentyang.com. 3600 IN A 185.199.111.153
trentyang.com. 3600 IN A 185.199.110.153
trentyang.com. 3600 IN A 185.199.109.153
trentyang.com. 3600 IN A 185.199.108.153



  • Once the above is successful, your custom domain should work correctly. Go to your domain and take a look!

STEP 3/4: Let your www sub-domain (www.trentyang.com) point to your github pages

  • Add the following CNAME record
    CNAME record

  • You can use the following dig command to confirm that your setup is correct

    Enter fullscreen mode Exit fullscreen mode

$ dig www.trentyang.com +nostats +nocomments +nocmd
www.trentyang.com. IN A
www.trentyang.com. 1263 IN CNAME chun-yang.github.io.

Enter fullscreen mode Exit fullscreen mode




STEP 4/4: (optional but HIGHLY recommended) Enable HTTPS for your github pages

  • Go to your github repository settings page, under Settings > GitHub Pages > Custom domain remove your custom domain and save. GitHub Settings Github Pages
  • Then add it back and save again.
  • Now you should be able to check the "Enforce HTTPS" checkbox and secure your site!

If you enjoy reading it, here is my blog https://trentyang.com/how-to-setup-google-domain-for-github-pages/

Latest comments (26)

Collapse
 
lenakroeker profile image
Lena Kroeker

thanks so much! It finally works!!!!!
I must've gone through 10 or more tutorials trying to get this all to come together, accidentally almost lost my whole project a few times somehow etc etc. Nightmare! sometimes you just need to start from scratch a bunch of times before you get the right combo, and this did it for me!

Collapse
 
siddacool profile image
Siddhesh Mangela

how to do subdomain for example

blog.mysite.com

Collapse
 
gsharm profile image
Gaurav Sharma

Worked great - thanks!

Collapse
 
jwsmitherman profile image
jwsmitherman

I can't seem to get this to work. I've deployed my react app to my git hub pages. I tested it without the custom domain and it came up fine. But when I attempt to add the custom domain it never shows following these steps. I'm at a road block here so any help would be very much appreciated.

Collapse
 
nikijiandani profile image
Nikita Jiandani

Nice article! Works as expected. Thank you!!!

Collapse
 
tashanduncan profile image
Tashan Duncan

Saved me some headache here!

Thank you

Collapse
 
jakkapanksb profile image
Jakkapan

Thanks, Absolutely nice tutorial

Collapse
 
brpetrucci profile image
Bruno do Rosario Petrucci • Edited

Hi, thanks for the great tutorial! I'm getting an error, not sure where.

Everything seems to be working correctly - dig commands lead to the same output you show, the website shows up with a check in github "ready to be published at brpetrucci.com" etc, but when I try the URL it says the page cannot be found? I'm very confused

Collapse
 
fr3drick545 profile image
fr3drick545

I have the same issue. Have you been able to find a fix?

Collapse
 
thecarpathiancoder profile image
TheCarpathianCoder

Thanks man!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.