Get the latest updates, in-depth tutorials, and exclusive resources on themes, templates, and code. Stay ahead with our expert insights—join our Telegram channel today!

How to Add a Custom Domain to GitHub Pages

Learn how to add a custom domain to GitHub Pages with DNS setup and CNAME configuration.

Adding a custom domain to your GitHub Pages site gives it a professional look and enhances your brand identity.

GitHub Pages Custom Domain Setup Guide
Step-by-step guide to configure a custom domain for GitHub Pages.

This guide will help you configure a custom domain (e.g., www.example.com) for your GitHub Pages website.


Why Use a Custom Domain?

  • Improves branding and credibility.
  • Enhances SEO rankings.
  • Allows multiple projects under one domain (e.g., blog.example.com, docs.example.com).
  • Provides better control over website URLs.

Prerequisites

Before you proceed, ensure you have:

  • A GitHub Pages site already set up.
  • A custom domain purchased from a registrar (e.g., Namecheap, GoDaddy, Cloudflare).
  • Access to your DNS settings via your domain provider.

Step 1: Configure GitHub Pages

  1. Open your GitHub repository.
  2. Navigate to Settings > Pages.
  3. Under Custom domain, enter your domain name (e.g., www.example.com).
  4. Click Save, and GitHub will suggest DNS records.

Step 2: Update DNS Records

To connect your domain to GitHub Pages, configure your DNS records with your registrar.

For Root Domain (example.com):

  • Add A Records pointing to GitHub Pages IP addresses:

    Type Name Value TTL
    A @ 185.199.108.153 Auto
    A @ 185.199.109.153 Auto
    A @ 185.199.110.153 Auto
    A @ 185.199.111.153 Auto

For Subdomain (www.example.com):

  • Add a CNAME record:

    Type Name Value TTL
    CNAME www your-github-username.github.io Auto

📌 Example: If your site is hosted at yourusername.github.io, your CNAME should point www to yourusername.github.io.


Step 3: Add a CNAME File in Your GitHub Repository

  1. In your GitHub repository, go to the root directory.
  2. Create a new file named CNAME.
  3. Inside the file, add your custom domain (e.g., www.example.com).
  4. Commit and push the file.

Step 4: Enable HTTPS (Optional but Recommended)

  • Go to GitHub Settings > Pages.
  • Check the Enforce HTTPS box.
  • GitHub will generate an SSL certificate (may take some time).

Troubleshooting Tips

Issue: Domain Not Working

✅ Double-check DNS records and propagation status (DNS Checker). ✅ Ensure the CNAME file in your repository is correct. ✅ Allow some time for DNS propagation.

Issue: SSL Certificate Not Available

✅ Enable Enforce HTTPS in GitHub Pages settings. ✅ Wait for GitHub to generate the certificate. ✅ Remove any conflicting SSL settings from your registrar.


Conclusion

Adding a custom domain to GitHub Pages is a simple yet essential step to enhance your website's professionalism and accessibility. Follow these steps, and your custom domain will be live in no time!

🚀 Try it out and elevate your GitHub Pages site today!

My name is It Is Unique Official, and I write news articles on current threats and trending topics. I am based in Parbhani, Maharashtra, India.

Post a Comment

Please avoid spamming in the comment section; all comments are moderated by the admin for quality and relevance.