Steps to set up a website with a custom domain
- Purchase a domain name from your favourite domain name registrar (Google Domains, NameSilo, GoDaddy etc.)
- Sign up for GitHub and create a repository on GitHub by clicking the “New repository button” and completing the required details.
- Add your website files to the repository you created (see my Git cheat guide if you’re new to Git). In the repository directory containing the website files type:
git checkout -- orphan gh-pages
git add *
git commit -m "Added website pages"
git push origin gh-pages
- To set up the custom domain on GitHub you must:
- add a file named CNAME to your repository. This file should only contain one line which is your domain. For example, the line example.com
- In the settings tab on your repository in GitHub, type your custom domain (e.g. example.com) and click the “Save” button.
- Let your domain registrar know about the GitHub custom domain by setting up a custom DNS.
- Log into your registrar’s settings page and set up a custom DNS pointing to GitHub. The custom IP addresses used by GitHub Pages are 220.127.116.11 or 18.104.22.168 as shown here. The DNS settings, which should be recorded in your registrar’s A record, are also available here. Create a CNAME record pointing http://www.example.com to <username>.github.io. Some domain name registrars have a GitHub template you can use instead of manually setting everything up.
- Optional: set up an alias email using email forwarding with your registrar.
Now you can type example.com in your web browser and this will navigate to the website you uploaded to GitHub!
- My website works fine for URLs of the form “example.com” but not for “www.example.com” A workaround for this is to configure forwarding with your domain name registrar. Simply forward http://www.example.com to example.com. This is dangerous because it leads to too many redirects which are restricted on most browsers.
- I get an error about my CNAME file Check out the official troubleshooting guide for a range of CNAME errors and solutions.