degit: Error: "Could not find commit hash for master"

Hey there—I’m trying to get started with Svelte and running:

Environment:

  • macOS 10.14 Mojave
  • Node v8.11.4
  • degit v2.1.3

Running:

degit sveltejs/template-webpack

… gives me:

! could not find commit hash for master

Double checking that the user/repo is correct, I’m not really sure why it can’t find the hash. I tried it with a couple other repos out there and no-go.

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 16
  • Comments: 44

Most upvoted comments

Setting the cache value to false in the degit options solved this for me:

degit(repo, {
      cache: false,
      force: true,
      verbose: true,
    });

Well derp, I was trying to run this on a new Macbook Pro that I hadn’t installed Xcode or the Command Line Tools on, so git wasn’t ready to go yet. Now that it’s installed, I tried degit again and everything worked like a charm.

It may be pertinent in the rare cases when people don’t have git properly configured (who even does that?!) that degit properly pass any errors along that may occur like this.

I run this “degit sveltejs/template my-svelte-project” on git terminal not the cmd … and it works . just right click then choose git bash here and run the command there . I hope that will be helpful .

I was just looking into getting degit to display more helpful error messages when it runs into a problem, and I found that it does display the underlying error if you call it with the verbose -v flag. Does it make sense to always display that error? I’m hoping that will eliminate a lot of questions in Svelte issues and the chatroom about this. In the meantime, now that I know this, I suppose we can tell people to run it again with -v so we can get some sort of idea of what’s happening.

Edit: Or perhaps less intrusively: a gentle extra note that’s displayed when there’s an error with verbose mode off that the user can add -v to get more logging.

@cogoo, in the most cases, this error occurs when git isn’t available/installed.

I have git installed. With cache: true it attempts to find the repo from a local cache, which is what caused the error for me

@paulocoghi

I know this thread is covering a lot of different issues now, but I had the same “could not fetch remote”:

npx degit "sveltejs/sapper-template#webpack" sapper-test
! could not fetch remote https://github.com/sveltejs/sapper-template
! could not find commit hash for webpack

but it turns out that my .gitconfig in my home directory had an invalid http proxy that I could no longer access. Hope this helps someone.

thanks @cogoo it worked !!

git update helped on windows 10

turns out the github repo is at sveltejs/template not svelte/template and as such the command should be npx degit sveltejs/template <your-project-name>

A PR adding a check to see which branch is available between main and master can solve the scenario mentioned by @netaisllc .

Edit:

This PR (#243) from @fregante , provides an even better approach: read the default branch.

Note that Github itself has seemingly begun to default new repos to a main branch.

Today I ran into what looked like a degit issue (! could not find commit hash for master) which actually wasn’t degit’s problem. There indeed wasn’t a master branch. As soon as I created one and ran degit again there was much joy.

@bernardoadc , you are right 👍 I had not thought about this possibility and, in this case, it is interesting that degit uses git.

Since gittar is a good alternative when all you want is to clone public repos, I believe that we have good options for any case.

@masterl , unfortunately you are right.

As mentioned by @cogoo and @riazXrazor, when using degit on code (not as cli), setting cache to false on the options may solve this problem

But it seems that we can’t do the same on cli.

@cogoo, in the most cases, this error occurs when git isn’t available/installed.