When attempting to download a private GitHub repository using go mod tidy, users may encounter an error message similar to:
not found: github.com/me/[email protected]: 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.
This issue arises due to the absence of proper credentials in the configuration files. To resolve this:
Modify ~/.gitconfig:
Replace:
[url "ssh://[email protected]/"] insteadOf = https://github.com/
With:
[url "https://{{username}}:{{access_token}}@github.com"] insteadOf = https://github.com
where {username} is your GitHub username and {access_token} is your personal access token.
Create ~/.netrc File:
Ensure a ~/.netrc file exists with the following content:
machine github.com login {{username}} password {{access_token}}
Set GOPRIVATE Variable:
Verify that your private repository's domain is specified in the GOPRIVATE environment variable, e.g.:
export GOPRIVATE=github.com/your_domain
Following these steps should enable go mod tidy to successfully download the private GitHub repository.
The above is the detailed content of How to Fix \'go mod tidy\' Failure When Downloading a Private GitHub Repository?. For more information, please follow other related articles on the PHP Chinese website!