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:
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.
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.
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.
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!