How to add a Custom Domain to Github Pages?

J Rui Pinto
Boring Notebook
Published in
3 min readNov 29, 2020

--

Photo by NASA on Unsplash

This article explains how to set a custom domain name on github’s hosted websites (github pages).

I don’t know if the problem is only me but I always find the Github Documentation difficult to understand. Sometimes I find myself searching for a simple answer, for a very simple problem but what I always find is a very confuse and extensive answer that I need hours to digest.
So, this is my simple answer to the simple problem of add a custom domain to my github’s repositories docs / github’s hosted websites.

1. Create “CNAME” file

screenshot of CNAME file beeing edited

Create a file named “CNAME” (in capital letters without quotes), in the root of your project repo and write your custom domain inside it. Like “example.com”.

2. Set “CNAME” record

screenshot of DNS Management console editing “www” CNAME record

In your DNS Management console, add a record with the following parameters:

type = CNAME
name = www
value = username.github.io

PS: some DNS Management consoles need you to add a dot (“.”) at the end of the value (like “username.github.io.”) but “dominios.pt” don’t (it actually won’t let you add any special character in the end).

2.1. Api subdomain (optional)

If you need a subdomain in your website (as “api.example.com”) you may add another CNAME record with name parameter set to api

type = CNAME
name = api
value = username.github.io

3. Set “A” records

In your DNS Management console, add 4 records with the following parameters:

type = A
name = example.com
value = 185.199.108.153 // this IP is different for each of the 4 records

To check wich are the most up-to-date IPs of Github Pages to set in your records search in github pages custom domain docs

References:

--

--

J Rui Pinto
Boring Notebook
0 Followers

I am a self-taught Angular Developer specialized in RxJS and electronics. I mostly write technical reminders but I’m happy if they help you too.