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 gh-pages.

In your root, have a CNAME file with the line

Commit and push.

GitHub Pages

Create a new repository on GitHub for the project.

git remote add origin
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:

@              A (Address)
@              A (Address)
www     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 +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!