gh-pages icon indicating copy to clipboard operation
gh-pages copied to clipboard

Deploying seems to overwrite custom domain

Open unlikenesses opened this issue 8 years ago • 25 comments

I am deploying a GatsbyJS site to GitHub pages with this command:

gatsby build --prefix-paths && gh-pages -d public -b master

I need to push to the master branch because it's a user site (rather than a project site). This works but each time I do it, the repo's "Custom domain" setting is reset. This means after every deploy I need to go into the settings and re-enter the custom domain. No idea if this is a bug or if I'm just missing something obvious.

unlikenesses avatar Nov 13 '17 10:11 unlikenesses

also getting this bug...

atav32 avatar Nov 15 '17 19:11 atav32

@unlikenesses @atav32

It seems you need to include a file named CNAME at the root of your file structure.
Your custom domain should be the first line in this file.

In my case, the CNAME file would have this content:

youfoundron.com

Credit goes to this comment.

youfoundron avatar Nov 24 '17 15:11 youfoundron

Just adapt this lines to your DEPLOYMENT script

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

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

pablorsk avatar Dec 23 '17 20:12 pablorsk

I came across the same issue and just added a npm script for this before publishing.

"add-domain": "echo \"customdomain.com\" > build/CNAME",

dijs avatar Feb 13 '19 17:02 dijs

If you use gh-pages for React app deployment – just put CNAME file with your domain into public folder.

vittorio avatar Mar 30 '19 14:03 vittorio

For angular 8. Create a CNAME file inside the src folder. then Inside angular.json "assets": [ "src/favicon.ico", "src/assets", "src/CNAME" // This is the change you need to make. ],

giteshjha avatar Jan 30 '20 17:01 giteshjha

It would be nice if this behavior was documented in the README.

dhedegaard avatar Feb 07 '20 21:02 dhedegaard

If you use gh-pages for React app deployment – just put CNAME file with your domain into public folder.

Thank you it helped

harivamshi81189 avatar May 31 '20 18:05 harivamshi81189

If you are using Gatsby just create a CNAME file inside the static folder and put your domain inside it like example.com

MohammedAl-Mahdawi avatar Oct 09 '20 23:10 MohammedAl-Mahdawi

I'm using no react just plain html css js. How do I resolve this issue?

rjitsu avatar Dec 20 '20 06:12 rjitsu

As others have said, just put a CNAME file that contains only your domain in the directory that is being published. This will work independently of what tools you are using.

joshsny avatar Dec 23 '20 18:12 joshsny

I'm using no react just plain html css js. How do I resolve this issue?

@rjitsu just put a CNAME to your root folder

pruthvi2103 avatar Feb 07 '21 12:02 pruthvi2103

I have a CNAME file in my root folder and it still resets the domain.. Any suggestions?

iamlasse avatar Apr 12 '22 08:04 iamlasse

@iamlasse

Is the CNAME file present at root after building for your github pages branch?

If not, which tool are you using to bundle your static assets?

youfoundron avatar Apr 12 '22 18:04 youfoundron

Please see your gh-pages branch and see if it has a CNAME file in it

pruthvi2103 avatar Apr 12 '22 20:04 pruthvi2103

For Hugo, I moved the CNAME file to the "public" directory as that is where the static site resources and assets are built by the GitHub Action.

makenziebird avatar May 11 '22 11:05 makenziebird

@iamlasse

Is the CNAME file present at root after building for your github pages branch?

If not, which tool are you using to bundle your static assets?

Yes, the CNAME file is in the root in gh-pages branch with the domain as the only text inside.

iamlasse avatar May 11 '22 12:05 iamlasse

same problem here: CNAME file is in the build/ folder, but the custom domain keeps resetting...

flaviusburca avatar May 28 '22 10:05 flaviusburca

same problem here. CNAME available in the gh-pages branch root folder and the GitHub Pages custom domain keeps resetting on every deploy

dimitarangelkov avatar Jun 08 '22 13:06 dimitarangelkov

I was also having this same issue as @dimitarangelko. It turned out the issue was that there were slightly different formats of the link in the CNAME files and In the package.json "add-domain": script line

it was "add-domain": "echo "https://mypage.app" > build/CNAME", and it had https://mypage.app/ in the gh-pages branch CNAME file, but had just mypage.app in the master branch CNAME file. I switched them all to just mypage.app like so

public/CNAME (in master): mypage.app CNAME file (in GH-Pages): mypage.app and in package.json: "add-domain": "echo "mypage.app" > build/CNAME",

made sure that the correct domain was set up in github pages before doing this and pulled them in in the gh-pages branch. Saved it all and ran npm run deploy and it finally didn't replace it!

rivka99 avatar Aug 05 '22 23:08 rivka99

CNAME file is in my main and gh-pages branches, and at the root of each. But this still happens. Any ideas?

I'm building a Vite React app, I use GitHub actions to build and push to gh-pages branch.

SaadBazaz avatar Nov 14 '22 14:11 SaadBazaz

For Hugo (as mentioned above) you can add the CNAME like so from the root of your directory:

$ mkdir -p public
$ echo 'www.<yourdomain>.com' > public/CNAME

Adding this because I wasn't sure exactly where the public directory should be, and I didn't know what a CNAME file contained.

angles-n-daemons avatar Jan 18 '23 19:01 angles-n-daemons

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

fguisso avatar Oct 16 '23 15:10 fguisso

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

I am using Sphinx, but I fixed this by adding CNAME to the directory from which Pages deploys the source.

E.g., if your build.yml is directing Pages to use the build/ subfolder of root for deployment, then add CNAME to build/ in the main branch.

ani-per avatar Oct 19 '23 20:10 ani-per

I have the same problem using Hugo.

  • I'm using the deploy from branch gh-pages
  • the CNAME is set in both branches main and gh-pages

I think this worked fine before the option deploy using github actions, and I never chose this option because I have my own actions to build and update the branch gh-pages. I think that the problem is something in the new way that github handles the deployment.

I am using Sphinx, but I fixed this by adding CNAME to the directory from which Pages deploys the source.

E.g., if your build.yml is directing Pages to use the build/ subfolder of root for deployment, then add CNAME to build/ in the main branch.

I do that. https://github.com/fguisso/fguisso.github.io/blob/gh-pages/CNAME

image

I follow the file to show to you and noticing that every deploy removes de CNAME file, but this actions is not setting by me: https://github.com/fguisso/fguisso.github.io/commits/gh-pages/CNAME

fguisso avatar Oct 21 '23 14:10 fguisso