I am aware that on GitHub you can create a repository, <username>.github.io
, which will be a personal website. I also understand you can link custom domains to this, so example.com
would show the website in your GitHub repo.
I have a couple questions though.
At the moment, I have a GitHub project - let's call it FooProject
. I have purchased a custom domain name for a website to showcase the project. How can I create a website for this, hosted on GitHub? (not a personal site in the form <username>.github.io
, but a project site).
Also, can I give the GitHub repository a different name like fooproject.com
, or does it something specific?
I suppose what I am really asking is, when hosting a website on GitHub...
Can you host your website using a GitHub repository of any name (like fooproject.com
)?
If not, I'm aware of using gh-pages
branches for the website of a project. How would this work with a custom domain?
If that isn't a good option either, what's the best option for my use case?
Hope that's clear.
On GitHub, navigate to your site's repository. Under your repository name, click Settings. In the "Code and automation" section of the sidebar, click Pages. Under "Custom domain", type your custom domain, then click Save.
Follow the below steps to publish your own website onto GitHub Pages with a custom domain for absolutely no charges.
You can customize the domain name of your GitHub Pages site. GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.
So I managed to answer my own questions in the end - here's what I did.
My website is going to be something to showcase a different project I am working on. I could have hosted the website from a /doc
directory or gh-pages
branch in my project repository and then set up a custom domain from there.
However, there was also the option of creating a repository with any name and hosting the website from the master
branch - this method appealed to me more.
I created a new repository named the same as my domain name, example.com
(it doesn't really matter what you call the repository). Then, using git, I added some website files - index.html
, stylesheet.css
, etc.
Once my repository was ready, I configured its master
branch as a publishing source for GitHub pages - see this help page for details.
Then with my DNS provider (GoDaddy, in my case), I configured the CNAME
and A
records (for the www
subdomain and apex domain respectively). There are also help pages on GitHub for setting up www
subdomains and setting up apex domains. Note that it takes a little while for the changes made on the DNS to take effect.
Finally, I added my custom domain to my GitHub repository - see the GitHub help page for adding or removing custom domains.
Here's a summary (for using any GitHub repository to host a website):
master
branch as a publishing sourceCNAME
and A
records with DNS providerIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With