How to publish your GitHub pages on a domain
Publishing your GitHub pages is a two step process: you first configure GitHub and then set the DNS.
Assuming that you already pushed the website to GitHub, go to “Settings”.If you already didn’t so, rename your repository as <mysite>.github.io: this will publish your repository as <mysite>.github.io.
Now scroll down to find the “GitHub Pages” section. Publish the master branch:
Enabling HTTPS is not mandatory but is strongly suggested.
Specify your custom domain:
Now it’s time to create a special file in the root directory of the site repository, the CNAME file:
This file contains only one text row, specifying the pointing domain:
On DNS management
Before making changes, backup your current DNS configuration.
In your DNS management interface (I will refer to Aruba provider), add the following A records (as stated in this help page on GitHub), without specifying an host name:
If the www host is defined in A record, remove it, because you are going to add it as CNAME record.
Now on with CNAME records. Add a www host, pointing to <mysite>.github.io. (replace <mysite> with the real name of your repository name): don’t forget to add the dot (.) at the end of the hostname!
If everything is ok, you should see a green banner in the Setting section of the published repository.
Please allow some hour to DNS to propagate and enjoy your website!
Bonus track: adding a subdomain
You can publish a subdomain like blog.mysite.com, creating and publishing another repository on GitHub with a CNAME file specifying the subdomain name in its content:
In your DNS management interface, create another CNAME record with “blog” as hostname and pointing again to <mysite>.github.io. (dot included!)
GitHub will take care to publish the correct repository on the corresponding subdomain.