Go语言 无法读取“https://www.example.com”的用户名github.com:在Windows上禁用终端提示

xzlaal3s  于 2023-04-18  发布在  Go
关注(0)|答案(1)|浏览(258)

我试图使用go get -u <github_private_repo_link>从私有存储库中获取一些依赖项,但它一直失败,并出现以下错误:

  1. server response:
  2. not found: github.com/..../v3@v3.11.1: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/168bff8af96cdfac9cbe3ad64f7753732f8a19d99f7f1e897f19371e1ea453d9: exit status 128:
  3. fatal: could not read Username for 'https://github.com': terminal prompts disabled
  4. Confirm the import path was entered correctly.
  5. If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

我已经尝试导出set GIT_TERMINAL_PROMPT=1,但没有发生任何事情,发出相同的错误。有没有什么办法去得到将忽略此变量的值在windows上的go 1.13

whhtz7ly

whhtz7ly1#

尝试为GitHub设置临时凭证处理程序:

  1. GIT_USER="your-github-username-or-email"
  2. GIT_PASS="PAT"
  3. git config --global credential.helper "!f() { echo \`"username=`${GIT_USER}`npassword=`${GIT_PASS}\`"; }; f"

或者安装github cli并使用gh auth login进行github认证。
并查看错误消息中提到的文档以获取其他选项:
Git可以配置为通过HTTPS进行身份验证,或者使用SSH代替HTTPS。要通过HTTPS进行身份验证,可以在git查询的$HOME/.netrc文件中添加一行:

  1. machine github.com login USERNAME password APIKEY

对于GitHub帐户,密码可以是个人访问令牌。
Git也可以配置为使用SSH代替HTTPS来匹配给定前缀的URL。例如,要对所有GitHub访问使用SSH,请将以下行添加到~/.gitconfig

  1. [url "ssh://git@github.com/"]
  2. insteadOf = https://github.com/
展开查看全部

相关问题