How-to: Custom domain name for GitHub Pages
I host my personal blog on GitHub pages (datdev2409/my-blog). The default domain name for my website will be datdev2409.github.io/my-blog/. Now I want to create the custom domain name blog.datnguyen2409.tech to point to the GitHub pages
DNS Provider Config
For a subdomain (e.g., blog.datnguyen2409.tech)
Add the CNAME record point to the datdev2409.github.io (replace datdev2409 with your GitHub username)
The CNAME record should point to the hostname. Not the URL
❌ datdev2409.github.io/my-blog
✅ datdev2409.github.io
I use CloudFlare as the DNS provider. The config looks like below

For an apex domain (root domain e.g., datnguyen2409.tech)
Apex domain do not support CNAME record
Create the A records that point to the GitHub Pages IP Addresses
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153GitHub Config
Create the CNAME file with the custom domain name in the root of repository

Go to: Repository -> Settings -> Pages
- Input your custom domain in
Custom Domainsection - Check
Enforce HTTPSto enable HTTPS for website

References
GitHub Documentation: Managing a custom domain for your GitHub Pages site