DEV Community

Cover image for Set up websites using GitHub Pages

Posted on • Updated on • Originally published at

Set up websites using GitHub Pages

GitHub supports hosting static websites for free. Here we go through the essential steps.

Configure your own website

Firstly, create a new repository from GitHub website, name it, the username must match your GitHub account name exactly. Then, clone the repo and add a file index.html, add some texts into it, commit and push back. (This also applies to GitHub organization account.)

    git clone
    echo "Hello World" > index.html
    git add --all
    git commit -m "Init"
    git push -u origin master

Head back to the repo on GitHub in your browser, from Settings tab, scroll to GitHub Pages section, it will display something like:

"Your site is ready to be published at "

Great! Now your website is up and running now! And yes, it is ugly, therefore, you probably want to pick one from the static Site generators. There is another post going through the steps to generate sites using Hexo.

Customize domain

Go to Settings -> GitHub Pages to add a custom domain, e.g., and press Save. A file called CNAME will be automatically created at the root of the repository and contains the domain you have given. Now go to your DNS provider, add CNAME record, set Host to www and Value to, After done this www subdomain configuration, we continue to add A or ALIAS or ANAME record for apex domain, set Host to @ and point Value to

So that, will redirect to

Project Pages

For GithHub project page, there is no constraints for the repo name, any name works fine. And as long as there is an index.html in the root of the master branch, you can choose to host it from Settings -> GitHub Pages, then it will render the page properly. You can add some javascript and css files to polish the page, here is an example FYR. Similarly, you can just commit a docs folder to the repo and add a text or pdf file into it, and switch to master branch /docs folder to make it show up. Furthermore, using a static site generator to create more advanced website would be more fun and future steps.

Redirect existing site

In case you already have an existing site up and running somewhere else, assuming it's named It is possible to redirect your GitHub site to point to it if you wish. Just add the code below into your index.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting to</title>
<meta http-equiv="refresh" content="0; URL=">
<link rel="canonical" href="">

Learn more from the references in the bottom.


Top comments (0)