"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > 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 privat

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 privat

Published on 2024-11-16
Browse:199

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

* 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.

In order to solve this problem, you need:

  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 and {{access_token}} is your personal GitHub access token.

  2. Create .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 location of your private repository The name of the domain.

  4. Rerun go mod tidy.

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

As shown above, you need to provide 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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3