Home  >  Article  >  Backend Development  >  Here are several possible titles, choose the most appropriate one based on the content of the article: * 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

Here are several possible titles, choose the most appropriate one based on the content of the article: * 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 SarandonOriginal
2024-10-29 02:12:29269browse

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

* How to fix

go mod tidy is blocked and cannot download the GitHub private repository

When trying to use go mod tidy to download the GitHub private repository, you may encounter to the following error:

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.

To resolve this issue, you need to:

  1. Configure GitHub credentials in ~/.gitconfig.

    To do this, add the following line to your ~/.gitconfig file:

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

    where {{username}} is your GitHub username, { {access_token}} is your personal GitHub access token.

  2. Create the .netrc file.

    Execute the following command to create the .netrc file:

    touch ~/.netrc

    Then, add the following:

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

    Be sure to replace {{username}} and {{access_token}} with your own credentials.

  3. Add your private repository to the GOPRIVATE environment variable.

    Execute the following command to add your private repository to the GOPRIVATE environment variable:

    export GOPRIVATE=__YOUR_DOMAIN__

    where __YOUR_DOMAIN__ is the name of the domain where your private repository is located.

  4. Rerun go mod tidy.

    After disabling checksums you will be able to run go mod tidy successfully, but it is not a perfect solution.

As shown above, you need to provide your GitHub credentials so that go mod tidy can download your private repository. You will also need to add your repository to the GOPRIVATE environment variable to allow go to download private code.

The above is the detailed content of Here are several possible titles, choose the most appropriate one based on the content of the article: * 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. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn