Create Gatsby Project on a git initialized folder

Viewed 3054

I have a git folder with no files, so i wanted to use the Gatsby CLI to create a project in that folder. Using gatsby new . but failed that the repository is not empty but it only have .git folder only. What alternatives can i use to achieve my objective.

2 Answers

With gatsby new . you are setting the name of your project and the starter you want to clone (by default this one), in your case, it is an invalid syntax because you are setting neither the name nor the starter so it fails.

From Gatsby docs:

There are many Enterprise level companies that maintain an internal clone of the NPM registry for security purposes. If you work for such a company, you may find that you are able to successfully run npm install -g gatsby-cli but cannot run the gatsby new as the gatsby new command clones a repo from a public GitHub repository. Many companies block public GitHub, which will cause the gatsby new command to fail. Not to worry, though, you can set up a new Gatsby site without the gatsby new command with a few quick steps.

One easy thing you can do is to create your new project using gatsby-cli (like gatsby new test-project), cut all content, and paste it to your desired folder which is linked via .git folder to your repository.

Alternatively, you can create your project normally (gatsby new test-project) and then start your git (git init) and link it to your repository using:

git remote add origin remote <repositoryURL>
git add .
git commit -m "Initial commit"
git push -f origin master

More information about adding a remote here.

Another option is to create a gatsby project without using the new keyword. For that, in your desired project directory:

  • You will have to create an initialized package.json file by running npm init -y
  • then npm install gatsby react react-dom
  • then create a index.js file in src/pages directory
  • run gatsby develop

Now you have a gatsby development server up and running. In this way, you may not have all the configuration that comes with the starter project.

For more information: https://www.gatsbyjs.com/docs/setting-up-gatsby-without-gatsby-new/

Related