I had a website deployed to GitHub pages and wanted a custom domain for that, when I looked into the documentation, It was a little overwhelming, and of course it will be tough to understand for a beginner.
If you are doing something similar, go through these straightforward 2 steps and save your time :)
Before proceeding to the two steps, on how to use custom domain, I will brief on how to publish your website using GitHub pages. If you already have a GitHub page (Eg. somename.github.io), you can directly proceed to the step number #1 Adding CNAME to GitHub repo.
Since this is a tutorial article with straightforward steps, I will directly move to the steps :)
Of course, the first step is to create the repository for the website you wish to publish.
Let’s say (in my case) it’s MahdavBahlMD.github.io
The html file with name index.html
will be published as the home page. If there is no index.html file, then it searches for README.md
file and that markdown file will be published as the homepage.
You can also push the code for static website in a branch named gh-pages
and select that branch to be rendered/published in the next step. But there is no such hard and fast rule that you will have to publish gh-pages branch, you can simple deploy the master branch too.
Click on the settings tab.
Scroll down to GitHub Pages
section and select master branch
(or gh-pages branch
)
Note* Keep in mind that index.html
file will be rendered as the home page of published website, if index.html is not found, README.md
will be published, so keep the names of your files accordingly.
You can go to the published website after 15–20 seconds ( Your site is published at <address>
)
Follow these two steps!
First of all, you’ll need to add a CNAME file to your GitHub repo. Now, just as adding a normal file, it can be done by two ways.
One way is to create a new file called CNAME (without any extension) and in that file, add the domain name (Eg. theleanprogrammer.com in my case) then commit and push the changes from Git bash or your terminal.
Second way is to do it directly from GitHub,
That’s it, GitHub part is over
First step (adding cname) was to be done on your GitHub side, your own repo! The second step (adding A record) will be done on the side of your DNS provider.
In this step we will be creating an ALIAS
or ANAME
record, or simply, A
record that points to the IP (or domain) of GitHub pages server.
Doing this is very simple, all you need to do is find a section on the website of your domain name provider where you can add A records. Generally this section itself is called DNS. Once you find it, add the following IP addresses in the Points To
field.
185.199.108.153185.199.109.153185.199.110.153185.199.111.153
For complete documentation on setting up an apex domain, click here!
Found the article helpful?
TheLeanProgrammer | Subscribe_A Cadet Who Codes | A guide, teacher and mentor for those who want to learn programming and development, subscribe to be the first one to hear from me._http://madhavbahl.tech
Subscribe to TheLeanProgrammer to be the first one to get notified from me for future updates.
Feel free to reach out to me anytime if you want to discuss something :D
I would be more than happy if you send your feedbacks, suggestions or ask queries. Moreover, I love to make new friends and we can be friends, just drop me a mail.
Thanks a lot for reading till end. All the best and Happy Thinking! You can contact me in case if you need any assistance:Email: [email protected]: http://madhavbahl.tech/Github: https://github.com/MadhavBahlMDLinkedIn: https://www.linkedin.com/in/madhavba_hl/_