Buying the Name
Now it's time to secure a domain name for our website. Consider the name you would like to use for your site and search for it using a DNS (domain name system) registrar like: name.com, Google Domains, iwantmyname. (I will be using name.com for demonstration) Depending on the TLD (top-level domain—the part that immediately follows the "." of the url), most domain names are fairly cheap and usually only ask for a yearly fee.
When you've found the one you like, go ahead and purchase it.
Connecting the Name
Now that we have the name, we'll need to create a connection between our github pages repository and our domain name.
First, navigate to the settings panel of your github repository and scroll down to the github pages segment. Input your new domain name into the "custom domain" field.
Now, log into your DNS registrar and find the section to edit the DNS records for the domain name.
(Note that the screenshots and actions are particular to name.com and may differ based on your DNS provider)
Make sure that the type of record you are adding is an "A" record. We'll need to add 4 different A records that point to the following IP addresses:
You can leave the "host" section empty, but in the "answer" field paste the IP address and add each one individually.
Next, we'll make a CNAME record, with "www" in the "host" field and our domain name in the "answer" field:
This will create a redirect to our domain name if someone were to type "www." in front of our domain name. (all this information comes from here.)
That's all we need to do! The last step is to wait... It may take a few minutes before the server connects the domain to the repository, so try to exercise patience.
If it still doesn't work after a while, try opening the website using the new domain name in another browser or using another device to make sure the browser cache isn't causing problems.