`go mod tidy` 无法下载私有的 GitHub 仓库。

huangapple go评论85阅读模式
英文:

`go mod tidy` fails to download private GitHub repository

问题

以下是翻译好的内容:

这是回复的内容:

找不到:github.com/me/private-repo@v0.0.0-20220413034319-81fe8421f99f:无效的版本:git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/ea2baff0eaed39430ee011ad9a011101f13b668d5fcbd9dffdfa1e0a45422b40:退出状态 128:
致命错误:无法读取“https://github.com”的用户名:禁用终端提示
请确认输入的导入路径是否正确。
如果这是一个私有存储库,请参阅https://golang.org/doc/faq#git_https获取其他信息。

我尝试在~/.netrc中添加一个记录,其中包含新创建的GitHub个人访问令牌的密码,并在~/.gitconfig中添加配置

insteadOf = https://github.com/

所有这些都没有起作用。

如果我通过GOSUMDB=off go mod tidy禁用校验和,那么它可以工作,但我认为这对我来说不正确。

英文:

Here is the response

not found: github.com/me/private-repo@v0.0.0-20220413034319-81fe8421f99f: 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

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.

答案1

得分: 3

根据你的错误提示:

> 无法读取用户名

所以,你需要更改 ~/.gitconfig 文件:

将以下内容:

insteadOf = https://github.com/

更改为:

insteadOf = https://github.com

此外,你还需要创建 ~/.netrc 文件,并将内容设置如下:

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

注意:
请确保你的私有仓库位于 GOPRIVATE=__YOUR_DOMAIN__ 中。

英文:

As your error says

> could not read Username

So, you should change the ~/.gitconfig:

change this:

insteadOf = https://github.com/

to this:

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__

答案2

得分: 0

我建议使用以下配置:

insteadOf = https://github.com/

这样,任何 HTTPS URL 都将使用你的用户名。

并且,通过使用 Git Credential Manager(跨平台),你可以将你的 PAT(个人访问令牌)缓存在安全加密的本地存储中。

英文:

I would recommend:

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.

huangapple
  • 本文由 发表于 2022年4月13日 12:04:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/71851732.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定