`go mod tidy` fails to download private GitHub repository
Asked Answered
T

2

7

Here is the response

not found: github.com/me/[email protected]: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/ea2baff0eaed39430ee011ad9a011101f13b668d5fcbd9dffdfa1e0a45422b40: exit status 128:
    fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

I have tried to add a record in ~/.netrc with password of a freshly created GitHub Personal access token and add config in ~/.gitconfig

[url "ssh://[email protected]/"]
    insteadOf = https://github.com/

All these are not working.

If I disable the sum checking by GOSUMDB=off go mod tidy then it works yet I don't think this is correct to me.

Trashy answered 13/4, 2022 at 4:4 Comment(1)
Any progress on this one? I start suspecting it's a github bug. For me only one repo doesn't work like that, all other repos work fine.Commonweal
H
7

As your error says

could not read Username

So, you should change the ~/.gitconfig:

change this:

[url "ssh://[email protected]/"]
    insteadOf = https://github.com/

to this:

[url "https://{{username}}:{{access_toke}}@github.com"]
    insteadOf = https://github.com

also, you need the ~/.netrc file, with the content like this:

machine github.com login {{username}} password {{access_token}}

P.S: You should be aware that your private repository should be in your GOPRIVATE=__YOUR_DOMAIN__

Harbour answered 13/4, 2022 at 6:53 Comment(1)
In case the private repo belongs to an organization, you use a more specific url rewrite for the org only [url "https://{{username}}:{{access_toke}}@github.com/org"] insteadOf = https://github.com/orgArenicolous
S
2

I would recommend:

[url "https://[email protected]/"]
    insteadOf = https://github.com/

That way, any HTTPS URL will use your username.

And with a Git Credential Manager (cross-platform), you can cache your PAT (Personal Access Token) in a secure encrypted local vault.

Selfrising answered 13/4, 2022 at 7:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.