【问题标题】:`go mod tidy` fails to download private GitHub repository`go mod tidy` 无法下载私人 GitHub 存储库
【发布时间】:2023-02-01 16:16:03
【问题描述】:

这是回应

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.

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

[url "ssh://git@github.com/"]
    insteadOf = https://github.com/

所有这些都不起作用。

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

【问题讨论】:

    标签: git go go-modules


    【解决方案1】:

    正如你的错误所说

    无法读取用户名

    所以,你应该改变~/.gitconfig

    改变这个:

    [url "ssh://git@github.com/"]
        insteadOf = https://github.com/
    

    对此:

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

    另外,你需要~/.netrc文件,内容如下:

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

    附言:你应该知道你的私人仓库应该在你的GOPRIVATE=__YOUR_DOMAIN__

    【讨论】:

      【解决方案2】:

      我会推荐:

      [url "https://YourUsername@github.com/"]
          insteadOf = https://github.com/
      

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

      使用 Git Credential Manager(跨平台),您可以将 PAT (Personal Access Token) 缓存在安全的加密本地保险库中。

      【讨论】:

        猜你喜欢
        • 2022-01-01
        • 2017-02-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多