How to host a website on GitHub with custom domain
Tags: github, git, hosting
Published: 2022-12-23 11:27:03

In this article, we are going to learn how we can host a website on a GitHub page with a custom domain name.

I will upload my portfolio website on GitHub step by step.

First of all, we need to code your website and collect all the file and upload it to the GitHub repository.

If you don't know how to upload your code to the GitHub repository then let me know in the comment section, and I will write an article on the same.

Once the code is uploaded to the GitHub repository, Goto the same repository as shown in the below screenshot.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/no46atxdgyk5apfnvbqb.png)




In the above screenshot, we can see a lot of repositories are there. I am going to upload myPortfolio website so I will click on the same.

Once we will click on the repository that we want to upload we will get to see a setting icon as shown in the below screenshot.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s12nk5scbxxialmc2x20.png)



After clicking on the setting, we will find a section on the left side call pages. we will on that as shown in the below screenshot.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1gr50pa3mu112zsqhnpz.png)




Once we click on pages, we will see a source, we need to click on the dropdown and select "Deploy from a branch" as shown in the below screenshot.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1ijj4lnmrlqex4zm01q.png)




After that, we need to select the branch as the main and the folder as /(root) as shown in the below screenshot.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3kk9so5hhtrgtg9b8228.png)



After selecting the branch and folder, we will save it.

Once it's saved, we will go to our GitHub account settings as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/725813o5n0lwojuyppm7.png)




Then we will click on the pages on the left side as shown in the below screenshot.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e6n8yzvb87wklml0mrst.png)



When we click on pages, we will see a button called add a domain. we will click on that button as shown in the below screenshot.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1b5s5oxwjwao168dtpaf.png)



After clicking on Add a domain button, we will see a field where we need to give the custom domain name that we would have purchased from GoDaddy or any other domain name provider.

In my case, I have purchased from GoDaddy and my custom domain name is hussaincode.in so, I have given the same name as shown in the below screenshot.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j8pt03obdjp30f4zhsy8.png)



And then we can click on "Add a domain" button as shown above.

Once we will click on Add a domain button we will get some DNS TXT records as shown in the below screenshot that we need to add to our domain name provider like in my case on GoDaddy.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mmvy8wohxticlg8gr1ed.png)



We will copy this hostname and TXT record value and will go to our domain name provider and find the domain name DNS record.

First, we will go to the GoDaddy website and log in through our id and click on my product as shown below.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bk9lh4sk3xj1dpc6svgm.png)



Then we will go to the DNS of our domain name that we want to set up on the GitHub page as shown below.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aoszfbgc926tcpeolf26.png)



Once we click on DNS, we will find all the DNS records. In that record, we need to add the TXT record as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7csrfwg63kwtyowm5c2.png)




After clicking on add, we need to select the TXT record and put the hostname and its value that we copied from the GitHub TXT record during adding a domain.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwg9a50ds5l765qrgrse.png)



Once it's done we will save it and look for the CNAME record in the DNS if it's there we need to edit it and if it's not there we need to add the CNAME record and give the value as "hussaincode.github.io" where hussaincode is my username, you can check your username from your GitHub profile and change it accordingly.

Select all the values same as shown below just change the hussaincode with your username.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qyeid6ipwap1t9l5p8w.png)



We will check all the values if it's correct we will save them and then we will look for the "A" record in the DNS and give the value from this GitHub documentation as shown below.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2jr8wl1liizzppt7u29o.png)



After that, we will save this and come back to our repository settings again and will go to the pages.

And then at last we can see the custom domain field is there, we will give our custom domain name in that field and save it as shown below.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfwt6q2j4j8065dn3byw.png)



It will show as a DNS check in progress. We will wait for some time and it will show as the DNS check is successful as shown below

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k1fw7nz7gy2dc28aq96.png)




Once DNS is successful, our website will go live. we can check on our custom domain our website will be up and running.

In my case, my site hussaincode.in is up and running as shown in the below screenshot.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42qezbeh6jnwlqqv7bba.png)




Hurray, Our site is up and running using GitHub pages without and hosting coast.

If you have any doubt or get stuck at any point, comment it and I will try to help as much as possible.

Thank you all for reading this article, Hope it helps.