Gatsby: Problem with directory structure when deploying to Github Pages

Created on 4 Apr 2019  路  6Comments  路  Source: gatsbyjs/gatsby

Summary

I'm confused as to how a Gatsby project directory should look once you do npm run deploy. Currently, this command creates a new commit in our master branch that dumps all of our built files in the root folder, which completely ruins our nice directory structure with the src, public, static etc. folders. Pretty sure this is not the normal order of affairs.

Then when we undo this horrifying commit Github Pages will not be able to find an index.html file (?) and build our README.md - this is all we can see when we visit our live site

My question is should deploying our site to Github Pages ruin our directory structure like this? And if not, how do we achieve a proper deployment?

Relevant information

  • added "deploy": "gatsby build && gh-pages -d public -b master" to package.json scripts

  • gatsby build works fine

  • I found this blog post which seems to address our issue by creating a separate master-source branch and letting master just have the dump of built files. But I feel like this isn't the best/right way to go about things...

Environment (if relevant)

System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.9.4 - /usr/local/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.8.0 - /usr/local/bin/npm
Languages:
Python: 2.7.13 - /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Browsers:
Chrome: 73.0.3683.86
Firefox: 42.0
Safari: 12.1
npmPackages:
gatsby: ^2.3.3 => 2.3.3
gatsby-image: ^2.0.17 => 2.0.17
gatsby-plugin-catch-links: ^2.0.6 => 2.0.6
gatsby-plugin-emotion: ^2.0.5 => 2.0.5
gatsby-plugin-google-analytics: ^2.0.6 => 2.0.6
gatsby-plugin-manifest: ^2.0.6 => 2.0.6
gatsby-plugin-offline: ^2.0.9 => 2.0.9
gatsby-plugin-react-helmet: ^3.0.0 => 3.0.0
gatsby-plugin-sharp: ^2.0.32 => 2.0.32
gatsby-plugin-sitemap: ^2.0.1 => 2.0.1
gatsby-plugin-typography: ^2.2.0 => 2.2.0
gatsby-remark-images: ^2.0.4 => 2.0.4
gatsby-remark-prismjs: ^3.0.2 => 3.0.2
gatsby-source-filesystem: ^2.0.28 => 2.0.28
gatsby-source-instance-name-for-remark: ^0.1.1 => 0.1.1
gatsby-transformer-remark: ^2.1.8 => 2.1.8
gatsby-transformer-sharp: ^2.1.5 => 2.1.5
npmGlobalPackages:
gatsby-cli: 2.5.4

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

Most helpful comment

You have 2 options:

  • change the default branch from master to something else, and use master just as site deployment directory
  • have separate repository for your source code (so https://github.com/nzssa/nzssa.github.io is used only for deployment and not really for tracking your source code)

There's not much Gatsby can do about this limitation of github pages for orgs/users

All 6 comments

Good question! Also experiencing this issue

@luceliu So in your deploy script:

"deploy": "gatsby build && gh-pages -d public -b master"

The -b flag is which git branch it will commit the files to. By default, it will drop it into a gh-pages branch so you have that branch just containing the built site, but because you say -b master it is dropping all of the files in your master branch.

Try removing the -b master and then check if there is a gh-pages branch and if it contains only the files you wish to be there.

Thanks for the response @lannonbr ! Unfortunately, since our site is an organization page, we have no choice but to publish from our master branch, as Github details here. Perhaps this is why the blog post I mentioned had to offer that workaround?

Yeah if that is the case I think that blog post's solution may be how you will have to do such with separating the code and site to be deployed. May not be the cleanest but it's how it will have to be given GitHub's constraints

You have 2 options:

  • change the default branch from master to something else, and use master just as site deployment directory
  • have separate repository for your source code (so https://github.com/nzssa/nzssa.github.io is used only for deployment and not really for tracking your source code)

There's not much Gatsby can do about this limitation of github pages for orgs/users

Alright thank you both @lannonbr and @pieh for the input :-) closing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hobochild picture hobochild  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments