I put my ssh key in github so git clone works for a certain private repository; yet go mod tidy fails when trying to access the same repository, with the error message shown below. I could use help troubleshooting this problem. The error message from go mod tidy (redacting the name of the private repository, but otherwise verbatim) is:
github.com/[private repository path]: cannot find module providing package github.com/[private repository path]: module github.com/[private repository path]: git ls-remote -q origin in /mnt/dependencies/gopath/pkg/mod/cache/vcs/a1f499df6a9855aecdc77bda31504008583a3268fdd403799aade71bb47df7d2: exit status 128:
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository
Please make sure you have the correct access rights
and the repository exists.
The successful git clone command (again redacting the private repository) is:
git clone git@github.com:[private repository path].git
My .gitconfig file is (with my name and email redacted):
[user]
name = [my name]
email = [my email]
[url "github.com:"]
insteadOf = https://github.com/
[core]
excludesfile = /workdir/.gitignore
Other things that might make a difference:
- I am running commands as root in a Docker container.
- I tried to run
go mod tidyon my host with the same key in~/.sshas I have on the Docker container, and I got login prompts, which github no longer supports (they want SSH keys or personal access tokens). - The email in my gitconfig matches email given in the public key that I put on github.com.
A second, related question: Does the fact that I can run git clone rule out keys being uploaded wrong to github, and forgetting to enable SSO for the key on github?
Here is a similar question but it involves personal access tokens rather than ssh keys: `go mod tidy` fails to download private GitHub repository