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 (or your subdomain).

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 repository, 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)
@              A (Address)
@              A (Address)
www     CNAME (Alias)

For my configuration, I want both and to go to the website.

Note: The CNAME (Alias) record is for the subdomain www. It can be omitted if you are using only the root domain.

The CNAME is pointing to your github username, not the project name. GitHub will determine which project it is for via the CNAME file.

In the case where you are configuring for only a subdomain eg., then in your CNAME file you will have, and you only need to have the CNAME Alias (no need A Address).

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!




Back to Home