How to use customized domain for GitHub Pages

I managed to set up my own website(Blog, and personal homepage later) by GitHub Pages. The service provides default domains for the pages. But I would like to use my own domain.

Default domain

In detail, suppose that your GitHub username is <username>, then by default, the service gives the domains like:

  • For user page(in the special repository <username>, it provides the domain <username> for it.
  • For project page(in repository named <repo>), it provides the domain <username><repo> for it.

For more information, see the official documentation.

Buy own domain & Configure

I recommend namesilo to buy your own domain. Here is a good tutorial for it.

After that, use DNSPOD for DNS. It's easy: follow the instructions on DNSPOD to change the DNS server on namesilo DNS configuration page. After this step, everything you shall do is to configure DNS rules on DNSPOD, with no regard to the namesilo configuration.

Then we can transparent the domains by default.

To add coustomized subdomain and apex domain, see the official documentation. But here are some notations.

Firstly, If you change the user page domain <username> to customized domain <subdomain>, then all the repository pages will be on <subdomain><repo>. If the user page is not transparented, the repository page remains <username><repo>. However, if you configure any repository page with customized domain with no customized domain for user page, supposing the domain for <another-subdomain>, the link to <username><repo> will be resolved automatically into <another-subdomain><repo>, where no site is here. As a result, always give a main page,

Secondly, here are some methods to use one domain to jump to another domain. Here is a template:

At the repository where we want to jump to another, we use a 404.html file only, which contains

<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="utf-8">
<script language="javascript">
var domain = "<domain jump to>";
var current = window.location.href;
var target = current.substring(current.indexOf('/', current.indexOf(':') + 3));
window.location.href = "//" + domain + target;
location.href = "//" + domain + target;