How to Host a Website on Github Pages
GitHub Pages provides FREE hosting of your (static) website.
This post is a guide on hosting your “project” repository with a custom domain.
Your Local Repository
Instead of a
master branch, rename it to
In your root, have a
CNAME file with the line
Commit and push.
Create a new repository on GitHub for the project.
git remote add origin https://github.com/yourusername/yourproject.git git push -u origin gh-pages
If you have an existing respository, create a new
gh-pages branch, and make sure it is your default branch in your repos settings.
Configure Domain Name
GitHub does provide an article on how you can do it, but it is very confusing.
As an illustration, this is my configuration using namecheap:
@ 220.127.116.11 A (Address) @ 18.104.22.168 A (Address) www yourusername.github.io. CNAME (Alias)
Note: The CNAME (Alias) record is for the subdomain www. It is pointing to your github username, not the project name. GitHub will determine which project it is for via the CNAME file.
Wait for the DNS changes to propagate.
Or check with
dig example.com +nostats +nocomments +nocmd if changes are propagated.
That’s it. With GitHub Pages, you can host as many projects/websites as you want, for free!