首页  >  文章  >  后端开发  >  为什么 `go mod tidy` 无法下载我的私有 GitHub 仓库?

为什么 `go mod tidy` 无法下载我的私有 GitHub 仓库?

Mary-Kate Olsen
Mary-Kate Olsen原创
2024-10-28 03:36:31337浏览

Why Does `go mod tidy` Fail to Download My Private GitHub Repository?

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

使用 go mod tidy 从私有 GitHub 仓库下载模块时,用户可能会遇到错误,指出仓库由于版本无效而无法找到。即使使用个人访问令牌配置 ~/.netrc 并将 ~/.gitconfig 设置为使用 SSH 而不是 HTTPS,也可能会发生此错误。

此问题的根本原因在于 go mod tidy尝试从终端读取“https://github.com”的用户名,如果禁用,则会失败,如错误消息“致命:无法读取“https://github.com”的用户名:终端提示”所示已禁用。”

要解决此错误并成功下载私有 GitHub 存储库,请修改 ~/.gitconfig,如下所示:

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

其中 {{username}} 和 {{access_token}}应替换为您的 GitHub 帐户的相应值。

此外,确保使用以下内容创建 .netrc 文件:

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

最后,验证私有存储库是否为包含在 GOPRIVATE=__YOUR_DOMAIN__ 中。此配置设置将 go mod tidy 的使用仅限于指定域内的私有存储库。

以上是为什么 `go mod tidy` 无法下载我的私有 GitHub 仓库?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn