Publish Websites on GitHub Pages with a Custom Domain
Last Updated : 27 May, 2024
GitHub Pages is a free hosting service provided by GitHub that allows you to publish static websites directly from your GitHub repositories. By default, GitHub Pages provides a domain in the format - username.github.io/repository
, but you can also use a custom domain for your website. This article will guide you through the process of publishing websites on GitHub Pages with a custom domain.
Prerequisites
- A GitHub Account
- A GitHub Repository
- A Custom Domain
Steps to Publish Website on GitHub Pages
Step 1. Setup up a GitHub repository
Set up an empty GitHub repository just the way you normally do. Give any name to the repository. You could keep the repository either public or private, your choice.
Step 2. Push your code on the repository
Push the entire code onto the repository. Ensure that you have the index.html in the root directory or in a folder named docs (you’ll understand why in the next step).

Here's the directory structure:
- index.html
- public
|_ css
Step 3. Enable GitHub Pages
Head to the Settings tab of the repository and scroll down to where it says GitHub Pages. By default, the options look like this:

For the Source, click the dropdown where it says None and choose the branch where your code is present, in my case it’s main.
As soon as you select the branch, a new dropdown will appear. Choose the respective folder (root/docs) where your code is present. Click Save.
Scroll back down to the GitHub Pages section and you should see something like this:

Head to the URL and you should see your website live on the internet.
Step 4. Set a custom domain
In the next step, we’ll explain how to get a free custom domain.
Now to set up a custom domain, enter the domain name in the Custom domain section, in my case, it’s github-pages.tk
Click Save. This adds a new CNAME file to your repository.

Sometimes the Enforce HTTPS option is auto-enabled, if it’s not, enable it manually to get a free SSL certificate for your website. Sometimes, it could also take time to give you the option to enable it.
Step 5. Get a custom domain
To get free custom domains, I use Freenom. If you already have the domain from another provider, the below steps should be similar.
Login onto the website and goto Services > Register a New Domain and search for the desired domain name.
Select the available domain and complete the checkout process.

Now go to Services > My Domains. Select the Manage Domain option against the domain you just got and head to Manage Freenom DNS.
Now, all we need to do is set A & CNAME records for the selected domain.
For A record, add four entries:
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
To redirect www subdomain to the original domain, add a CNAME record with your GitHub pages profile URL with a .(dot) in the end, in my case, it would be ‘ishaanohri.github.io.’.

Just to be sure, check for the latest IPs in GitHub’s Official Documentation.
Save the records and wait for some time. Your website would be live on www.custom-domain.com and custom-domain.com. Sometimes it may take up to 24 hours to reflect the changes.
Your website is now live on your custom domain. Now, any changes you push onto the selected branch of the repository will be published live on your domain.
Similar Reads
How to Add Custom Domain To GitHub Pages?
Adding a custom domain to your GitHub Pages site can significantly enhance its professional appearance and make it easier for your audience to remember and access. This guide will walk you through the process step-by-step, ensuring you can easily configure your custom domain and optimize your site's
2 min read
How to Build Portfolio Website And Host It on GitHub Pages?
Having an online portfolio is important for showcasing your skills and accomplishments. GitHub Pages provides a convenient and free platform for hosting your portfolio website. In this article, we will see how to build a Portfolio Website And Host It on GitHub Pages. Table of Content Creating a Port
15 min read
How to Publish a Static Website on GitHub?
Publishing a static website on GitHub is a great way to share your work with the world. GitHub Pages is a service offered by GitHub that allows you to host your static websites directly from a GitHub repository. In this article, weâll walk you through the steps to publish your static website on GitH
6 min read
Deployment of React Application using GitHub Pages
Deploying a React application using GitHub Pages is an easy and efficient way to host your projects online for free. In this article, we will walk you through the steps to deploy your React app, making it accessible to users with a live URL. PrerequisitesA GitHub accountNode.js and npm installedBasi
4 min read
OAuth2 Authentication with Spring and Github
OAuth2 is a secure way to allow users to log in to your application using third-party providers like GitHub. Instead of creating a custom login system, we can use GitHubâs authentication to verify users and grant access. Working of OAuth2Imagine a user wants to log in to your app using GitHub. When
2 min read
How to Publish Docker Image to Dockerhub Using Github Actions?
Pre-requisites: GitHub Actions, Docker Hub Publishing Docker images to Docker Hub using GitHub Actions is a simple and efficient process that can automate your image-building and publishing process. What are Github Actions?GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) plat
3 min read
Deployment of Angular Application using Github Pages
There are various methods to deploy Angular Application such as Github Pages, Heroku, Firebase, etc. The Github provides the simplest way of all using the Github Pages. Steps to Create and Deploy Sample Angular Application to Github Pages: Install Node.js: a. Windows b. LinuxInstall Angular - CLICre
2 min read
Integrating Ansible with GitHub for CI/CD Pipelines
Many development teams face challenges when successfully combining several tools to form proper and effective CI/CD processes. An inefficient workflow means projects slow down, vary in their implementation, and have more overhead related to infrastructure management. Another consequence is that, due
8 min read
Connecting Custom Domain To Website Hosted On Firebase
Firebase is one of the best platforms to host a static website for free. When we have a website hosted on firebase we get two domains assigned to it. For example, the project id for my portfolio website which is already hosted on firebase is 'ankit-kumar-cv' therefore the URLs assigned to it were: p
4 min read
Getting Started With GitHub REST API
The GitHub REST API is a powerful tool that allows developers to interact with a list of features of GitHub. Whether you're automating tasks, building integrations, or simply managing your GitHub resources more efficiently, the REST API provides a versatile and accessible entry point. In this articl
5 min read