Table of Contents
Using a custom domain with GitHub Pages allows you to create a professional and memorable online presence. It helps reinforce your brand and makes it easier for visitors to find your site. This guide will walk you through the steps to set up a custom domain for your GitHub Pages website.
Prerequisites
- A GitHub account with a repository hosting your website
- Access to your domain registrar’s DNS settings
- A registered custom domain (e.g., www.yourdomain.com)
Step 1: Configure Your GitHub Repository
First, ensure your GitHub Pages site is set up correctly. Navigate to your repository’s settings, scroll to the “Pages” section, and confirm your site is published using the default github.io domain. Take note of the branch and folder used for publishing.
Step 2: Add a CNAME File
Create a file named CNAME in the root of your repository. Inside this file, add your custom domain name, such as www.yourdomain.com. Commit and push this change to your repository. This file signals GitHub to associate your custom domain with your site.
Step 3: Update DNS Settings at Your Domain Registrar
Log in to your domain registrar’s dashboard. You need to set DNS records to point your domain to GitHub’s servers.
- For A records, add the following IP addresses:
- 185.199.108.153
- 185.199.109.153
- 185.199.110.153
- 185.199.111.153
- For CNAME record, point www to yourgithubusername.github.io.
Step 4: Verify and Wait
After updating DNS records, it may take some time for changes to propagate. You can verify your setup by visiting your custom domain. If everything is configured correctly, your GitHub Pages site will load under your custom domain.
Additional Tips
- Use HTTPS for security. GitHub automatically provides SSL certificates for custom domains via Let’s Encrypt. Enable it in the “Pages” settings.
- Ensure your CNAME file is correctly committed to avoid conflicts.
- Check DNS propagation with online tools like DNS Checker.
By following these steps, you can elevate your GitHub Pages site with a professional custom domain, enhancing your branding and making your website more accessible to your audience.