Assuming you have already bought a custom domain (example.net) and a Github Page set up (example.github.io):
Create a CNAME file
Create a file name CNAME
in the project's root folder with the custom domain example.com
inside.
# Outputs example.net to a file named CNAME
echo example.net > CNAME
You may need to configure your build command to also copy CNAME
to the build folder, for example with a package.json
file with React:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && cp CNAME build/CNAME",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
Configure your domain
At your domain provider (the place you bought the domain - which I recommend porkbun.com), find the configuration for custom host/resource records and set:
Type: A
Host: @
Answer/Data/Value: 185.199.108.153
TTL: 30min (or any)
Do this for all 4 github page ip addresses: 185.199.108.153
, 185.199.109.153
, 185.199.110.153
and 185.199.111.153
You'll also need to add this one:
Type: CNAME
Host: www
Answer/Data/Value: example.github.io
TTL: 30min (or any)
Configure repository
At Github, go to the repository settings and add your custom domain in the Github Pages section.
It might take up to 24h to reflect these and/or HTTPS changes