Search code examples
javascriptreactjsgraphqlgatsbynetlify

Create Gatsby Project on a git initialized folder


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.


Solution

  • 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.