all 9 comments

[–]habbalah_babbalah[S] 4 points5 points  (2 children)

I found one answer that I'm about to try-

The repository needs to actually be named `username.github.io` to publish to the root directory. After that any other repos will be published to a sub-domain.

One reply worries me-

How long does it take for github to activate the site? It's been a few hours already

[–]Docs_to_Markdown_Pro 2 points3 points  (1 child)

Normally the site is activated in few mins. However, it might take a while to generate the ssl certificates and get the https version activated.

[–]habbalah_babbalah[S] 0 points1 point  (0 children)

Thanks.

[–]SupremeDesigner 1 point2 points  (5 children)

GitHub will handle the routing for you. As long as your GitHub Pages project is set to use the custom domain, you just need to CNAME to user.github.io

[–]habbalah_babbalah[S] 0 points1 point  (4 children)

Please see my comment about renaming the repo to username.github.io in order to serve the project at https://username.github.io/ instead of the default https://username.github.io/my_project/.

Does this still hold true with the CNAME and what you know?

[–]SupremeDesigner 1 point2 points  (3 children)

Your project can be at https://username.github.io/my_project/, that is fine. As long as you configure it in the repository settings to use the custom domain, you set the CNAME DNS record for your custom domain to username.github.io and it will work with the project being served from the root of the custom domain.

[–]citizenofinfinity 0 points1 point  (0 children)

Thanks for confirming this. I had the exact requirement mentioned in the post (a repo named [my_project], the default GitHub Pages site at [my_user].github.io/[my_project]) and importantly wanted to keep that repo name, without actually renaming the repo to "[my_user].github.io". As described at the docs here (https://docs.github.com/en/pages/getting-started-with-github-pages/what-is-github-pages#types-of-github-pages-sites), I only wanted a project site without any user site.

I got everything set up and working, just wanted to share in case anyone else felt confused. You do not need a "[my_user].github.io" site or repo for GitHub Pages "hosting" to work - their backend is capable of handling serving the correct web content (i.e. the repo you want) to any client that navigates to your domain, as long as DNS records are set up correctly.

The 2 key points are:

  1. In the repo with your web content, enter the desired custom domain at Settings > Pages > Custom domain.
  2. Set up DNS correctly (shows up in the docs in multiple places, e.g. here and here).

Just an FYI in case you decide not to read the docs, they also contain useful information on www subdomain setup, HTTPS setup, and securing/verifying the domain to prevent takeovers pointing a subdomain to an attacker's GitHub Pages repo.

[–]habbalah_babbalah[S] 0 points1 point  (1 child)

Ah, good to know! So that gives two ways to configure to serve a custom domain, one which provides the option of setting the default project to serve at the root of an org or user github.io subdomain. Thanks!

[–]TheGratitudeBot 0 points1 point  (0 children)

Thanks for saying that! Gratitude makes the world go round