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