Why Is My Github Pages Custom Domain Constantly Reset?
Asked Answered
I

5

16

I go into the page in Github (https://github.com/user/repo/settings/pages) and set a custom domain. It works great!

However, every time I deploy (using the gh-pages npm package) it resets the domain back to

 https://user.github.io/repo

This is incredibly frustrating... how can I tell it to use my custom domain permanently?

Isaac answered 20/4, 2021 at 17:29 Comment(0)
V
14

It looks like there are reports about this in the repo for gh-pages npm package. See #347, #236, #370, #213.

There is even a still opened merged pull-request that tackles the issue through documentation.

Basically, it says:

Modify the deployment line to your deploy script if you use custom domain. This will prevent deployment to remove the domain from settings in github.

echo 'your_cutom_domain.online' > ./build/CNAME && gh-pages -d build"

Edit: there are other options as well, some people directly change their deployment call and add a custom domain to their deployment scritpt:

var ghpages = require('gh-pages');
var fs = require('fs');

fs.writeFile('dist/CNAME', "your-custom-domain.com", function(err) {});
ghpages.publish('dist', function(err) {});

others just follow the advice for putting CNAME to your publishing folder.

Viviyan answered 20/4, 2021 at 17:58 Comment(2)
I got confused with the quotation mark around the domain name. Actually, it was not required.Tricot
"deploy": "echo domain.com > ./build/CNAME && gh-pages -d build"Tricot
G
3

For my React static site I have to add below scripts to the package.json to add the CNAME file with the custom domain to the build/ dir before each deployment.

"scripts": {
   "build": "react-scripts build",
   "add-domain": "echo \"myAwesomeDomain.org\" > build/CNAME",
   "deploy": "npm run add-domain && gh-pages -d build",
   "bd": "npm run build && npm run deploy",
},

Godding answered 15/6, 2022 at 1:50 Comment(1)
I had to remove the quotes around my domain name for this to work correctly for me. Thanks for the scripts though. They were quite helpfulValise
N
2

For those of you using the GitHub Action crazy-max/ghaction-github-pages there is a setting called fqdn that you're looking for. Set that with the custom domain and it stop breaking every deploy.

See documentation here.

Nannana answered 4/7, 2022 at 18:42 Comment(1)
Thanks, I just checked and the action I use - peaceiris/actions-gh-pages@v3 - has an analogous cname setting.Deltadeltaic
B
1

I was having the same problem for a gatsby site, I needed to install the gatsby-plugin-cname package and add the following to the gatsby-config.js

module.exports = {
  siteMetadata: {
    siteUrl: 'http://custom-domain.com/'
  },
  plugins: [
    'gatsby-plugin-cname'
  ],
}

https://www.gatsbyjs.com/plugins/gatsby-plugin-cname/

Biogen answered 17/7, 2023 at 22:20 Comment(0)
D
-1

If you are using "npm run deploy" or any npm deployment scripts Add a CNAME.txt file in public your Directory In the 1st line enter your custom domain name in it. e.g. (acbd.com)

else Create and Add the same in you static Directory

Deploy and check

Dedra answered 8/3 at 6:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.