Setting up a custom domain for GitHub project pages

I’m trying to configure a custom domain for my GitHub project pages. My repo has a gh-pages branch, and it works fine at myuser.github.com/myrepo. But I want to use my own domain, myexample.com, for these pages.

I’d like both myexample.com and www.myexample.com to show my project pages. The GitHub docs mention setting up an A record and a CNAME record in DNS. The A record part is clear, but I’m confused about the CNAME.

The docs talk about CNAME for user pages, but I only have a project repo. Do I need to create a user page repo just to use my custom domain? I’m hesitant to try because my site is already live.

GitHub support told me I can’t point both to the same gh-pages. That seems odd. Has anyone managed to set this up successfully? I’d really appreciate some guidance on how to make this work with my project pages.

hey there! i’ve done this before. u don’t need a user page repo. just add a CNAME file in ur gh-pages branch with ur domain (myexample.com). then set up DNS:

a record: @ → GitHub IPs
CNAME: www → myuser.github.io

it’ll work for both www and non-www. good luck!

I’ve encountered this issue before. You’re on the right track with the A record setup. For the CNAME, you don’t need a separate user page repo. Simply add a file named ‘CNAME’ to your gh-pages branch, containing only your domain (myexample.com). In your DNS settings, create an A record pointing your apex domain to GitHub’s IP addresses, and a CNAME record for ‘www’ pointing to yourusername.github.io. This configuration should work for both www and non-www versions of your domain. GitHub might take a short while to recognize the changes, so be patient. If issues persist, double-check your DNS propagation and GitHub repository settings.