Knowledgebase

How to Link Your Domain to GitHub Print

  • domain, github, cloudflare
  • 1

Linking your domain to GitHub Pages can be done efficiently with Cloudflare as your DNS provider. Here is a step-by-step guide to help you set up your domain to work with GitHub Pages.

Prerequisites

  1. A GitHub Repository: Ensure you have a GitHub repository with GitHub Pages enabled.

  2. Domain Name: You need a domain registered with us, click here to register your domain now.

  3. Cloudflare Account: Create a free Cloudflare account if you don’t already have one.

Step 1: Add Your Domain to Cloudflare

  1. Log in to Cloudflare:

  2. Add Your Site:

    • Click on Add a Site and enter your domain name.

  3. Choose a Plan:

    • Select the free plan or a paid plan depending on your needs and click Continue.

  4. Verify DNS Records:

    • Cloudflare will scan your existing DNS records. Review them and ensure they match the current records from your domain registrar.

  5. Update Nameservers:

    • Cloudflare will provide you with nameservers. Update your nameservers on your dashboard to the ones provided by Cloudflare. This step may take a few hours to propagate.

Step 2: Configure DNS Records in Cloudflare

  1. Access the DNS Settings:

    • In Cloudflare, navigate to the DNS section of your domain.

  2. Add an A Record:

    • Click on Add Record.

    • Select Type: A

    • Name: Enter @ for the root domain or the subdomain you want to use.

    • IPv4 Address: Use 185.199.108.153, 185.199.109.153, 185.199.110.153, and 185.199.111.153 (GitHub Pages IPs). Add four A records, one for each IP address.

    • Proxy Status: Set to DNS only (gray cloud).

  3. Add a CNAME Record (for subdomains):

    • If you’re pointing a subdomain to GitHub Pages (e.g., www.example.com):

      • Select Type: CNAME

      • Name: www (or your subdomain prefix).

      • Target: your-username.github.io.

      • Proxy Status: Set to DNS only (gray cloud).

Step 3: Configure GitHub Pages

  1. Open Your Repository:

    • Go to your GitHub repository.

  2. Enable GitHub Pages:

    • Navigate to Settings > Pages.

    • Under “Source,” select the branch and folder you want to use (usually main and /root for most setups).

  3. Set Your Custom Domain:

    • Under the Custom Domain section, enter your domain name (e.g., example.com).

    • Click Save.

  4. Verify GitHub Pages Certificate:

    • GitHub Pages will issue an SSL certificate. Ensure that “Enforce HTTPS” is enabled once the certificate is ready.

Step 4: Test Your Setup

  1. DNS Propagation:

    • It may take a few hours for DNS changes to propagate globally.

  2. Verify Domain Connection:

    • Open your browser and visit your domain (e.g., https://example.com) to ensure it’s correctly pointing to your GitHub Pages site.

  3. Troubleshooting:

    • Use tools like WhatsMyDNS to check DNS propagation.

    • Ensure Cloudflare’s records are correct and that GitHub Pages is properly configured.

Additional Tips

  • Redirect www to root domain:

    • In Cloudflare, create a CNAME record pointing www to your root domain if you want both www.example.com and example.com to work.

  • DNS Caching:

    • Clear your browser’s cache or flush your local DNS cache if changes don’t seem to take effect immediately.

By following these steps, you’ll successfully link your domain to GitHub Pages using Cloudflare. Enjoy your new website!


Was this answer helpful?
Back