Different repos corresponding to different sub-directories

For user.github.io, you can have different repos for different sub-directories. For example, user.github.io/dir1 can correspond to github.com/user/dir1. Can this be done for custom domains? I could not find any definitive answer, except for this StackOverflow post which suggests it is not possible.

Additionally, if it really is possible, does that mean that all those directories have to be on GitHub? If different directories are for different projects, all those projects would have to be hosted on GitHub.

Hi @igordot, welcome to the GitHub Community Forum!

Yes, this is possible to do! If you add your custom domain to a repository called igordot.github.io then your custom domain will be used in place of igordot.github.io for all sites hosted from your GitHub account.

You can then create new repositories and enable GitHub Pages and they’ll be hosted at https://example.com/repository-name/.

As for the second part of your question, yes, all these directories would need to be hosted on GitHub. You could use subdomains to host external sites on other hosting services though. For example, if you’re using your apex domain example.com on GitHub, you could host sites on external services using subdomain.example.com.

1 Like

Would this also work for multiple domains? For example, can I use example1.com with some repos and example2.com with others? Or can one GitHub account handle only one custom domain name?

It can only handle one inherited domain at a time—the domain that’s attached to your igordot.github.io repository. The domain that’s attached to this repository will be used for all other repositories under your account.

You can attach custom domains to these other repositories though, and serve them directly at any other domains you own, though these won’t use the directory structure, they’ll just be served directly from whatever domain you attach. You can only attach a custom domain to a single repository so you’ll only be able to use this domain for one repo.

But you can use subdomains for this too, so you can attach docs.example2.com to one of your repositories, and blog.example2.com to another, all while your other repositories are served from example.com/repository-name.

1 Like