I’m trying to configure a custom domain for my GitHub Pages project but running into some confusion with the DNS setup.
I currently have a project repository with a gh-pages branch that works perfectly when accessed through the default GitHub URL. Now I want to point my personal domain (let’s call it customsite.com) to serve this content, and I need both the root domain and the www version to work properly.
From what I’ve read in the GitHub documentation, I should create an A record and a CNAME record in my DNS settings. The A record part makes sense to me, but I’m confused about what exactly the CNAME record should point to.
The documentation mentions creating a CNAME for user page repositories, but that’s not what I have. I only have a project repository with the gh-pages branch, not a dedicated user pages repo.
My main question is: Do both customsite.com and www.customsite.com need to point to the same GitHub Pages project? Or do I need to create a separate user pages repository just to handle the www subdomain?
I contacted GitHub support but got a confusing response saying that both domains can’t point to the same gh-pages branch. This seems odd since most websites support both www and non-www versions.
Has anyone successfully configured both root domain and www subdomain to work with a single GitHub Pages project repository? I’d really appreciate hearing about your setup process.
I faced a similar situation a few months back. You can indeed use both your root domain and the www version for a single GitHub Pages project without needing a separate user repository. For the DNS configuration, set an A record pointing to GitHub’s IP addresses for your root domain and create a CNAME for www that directs to the root domain. In GitHub Pages settings, you can designate which version is primary; it will handle redirects for you. One important point is DNS changes might take some time to propagate, so be patient if things don’t work immediately.
That GitHub support response is incorrect. I’ve successfully run both the root and www versions from the same repository for over a year without issues. Here’s what works: Configure your A record for the root domain to point to GitHub’s IPs (185.199.108.153, 185.199.109.153, etc.). For the www version, create a CNAME record pointing to your username.github.io, not your root domain. In your repository’s Pages settings, select your primary version. GitHub manages the redirect automatically. Remember to enable HTTPS after the DNS changes propagate. Contrary to what the documentation states, a user pages repository is unnecessary.
that GitHub support person was wrong. I’ve been running both www and non-www on the same project repo for years without issues. just set your A records to GitHub’s IPs and point your www CNAME directly to username.github.io. don’t overthink it - the redirect happens automatically once you pick your preferred domain in settings.
Support probably gave you outdated info or there was some miscommunication. I set this up last year for a client and both domains definitely work with one repo. For DNS, point your root domain’s A record to GitHub’s servers, but set the www CNAME to your specific project URL (username.github.io/repository-name) - not just username.github.io. Once DNS propagates, add your custom domain in the repo settings under Pages. GitHub handles the www/non-www redirect automatically based on whichever one you set as primary. Just stay consistent with whatever format you enter in that custom domain field.