首页  >  文章  >  后端开发  >  以下是几个可能的标题,根据文章内容选择最合适的: * How to fix \"invalid version: git ls-remote -q origin\" error when using go mod tidy with private GitHub repositories? * Downloading private GitHub repositories w

以下是几个可能的标题,根据文章内容选择最合适的: * How to fix \"invalid version: git ls-remote -q origin\" error when using go mod tidy with private GitHub repositories? * Downloading private GitHub repositories w

Susan Sarandon
Susan Sarandon原创
2024-10-29 02:12:29269浏览

以下是几个可能的标题,根据文章内容选择最合适的:

* How to fix

go mod tidy遇阻不能下载 GitHub 私有仓库

在尝试用 go mod tidy 下载 GitHub 私有仓库时,您可能会遇到以下错误:

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.

为了解决此问题,您需要:

  1. 在 ~/.gitconfig 中配置 GitHub 凭据。

    为此,请将以下行添加到您的 ~/.gitconfig 文件中:

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

    其中 {{username}} 是您的 GitHub 用户名,{{access_token}} 是您的 GitHub 个人访问令牌。

  2. 创建 .netrc 文件。

    执行以下命令以创建 .netrc 文件:

    touch ~/.netrc

    然后,添加以下内容:

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

    请确保将 {{username}} 和 {{access_token}} 替换为您自己的凭据。

  3. 将您的私有仓库添加到 GOPRIVATE 环境变量中。

    执行以下命令以将您的私有仓库添加到 GOPRIVATE 环境变量中:

    export GOPRIVATE=__YOUR_DOMAIN__

    其中 __YOUR_DOMAIN__ 是您的私有仓库所在域的名称。

  4. 重新运行 go mod tidy。

    禁用校验和后,您将可以成功运行 go mod tidy,但这不是一个完美的解决方案。

如上所示,您需要提供 GitHub 凭据,以便 go mod tidy 可以下载您的私有存储库。您还需要将您的仓库添加到 GOPRIVATE 环境变量中,以允许 go 下载私有代码。

以上是以下是几个可能的标题,根据文章内容选择最合适的: * How to fix \"invalid version: git ls-remote -q origin\" error when using go mod tidy with private GitHub repositories? * Downloading private GitHub repositories w的详细内容。更多信息请关注PHP中文网其他相关文章!

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