无法读取“https://github.com”的用户名:在Windows上禁用了终端提示。

huangapple go评论104阅读模式
英文:

could not read Username for 'https://github.com': terminal prompts disabled on windows

问题

我正在尝试使用go get -u <github_private_repo_link>从私有仓库获取一些依赖项,但是它一直失败并显示以下错误:

服务器响应:
未找到:github.com/..../v3@v3.11.1:无效的版本:git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/168bff8af96cdfac9cbe3ad64f7753732f8a19d99f7f1e897f19371e1ea453d9: exit status 128:
致命错误:无法读取 Username for 'https://github.com':终端提示已禁用
请确认输入了正确的导入路径。
如果这是一个私有仓库,请参阅https://golang.org/doc/faq#git_https获取其他信息。

我尝试导出set GIT_TERMINAL_PROMPT=1,但没有任何效果,仍然出现相同的错误。在Windows上,对于go 1.13,有没有办法让go get忽略此变量的值?

英文:

I was trying to fetch some dependencies from a private repository using go get -u &lt;github_private_repo_link&gt; but it keeps on failing with this error:

server response:
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:
fatal: could not read Username for &#39;https://github.com&#39;: 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.

I've tried to export set GIT_TERMINAL_PROMPT=1 but nothing happens, the same error is issued. Is there any way go get will ignore the value of this variable on windows for go 1.13?

答案1

得分: 4

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

GIT_USER="your-github-username-or-email"
GIT_PASS="PAT"

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文件中添加一行:

machine github.com login USERNAME password APIKEY

对于GitHub帐户,密码可以是个人访问令牌。

Git还可以配置为对与给定前缀匹配的URL使用SSH代替HTTPS。例如,要为所有GitHub访问使用SSH,请将以下行添加到您的~/.gitconfig文件中:

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/
英文:

Try setting a temporary credential handler for GitHub:

GIT_USER=&quot;your-github-username-or-email&quot;
GIT_PASS=&quot;PAT&quot;

git config --global credential.helper &quot;!f() { echo \`&quot;username=`${GIT_USER}`npassword=`${GIT_PASS}\`&quot;; }; f&quot;

Or install the github cli and authenticate to github using gh auth login.

And check out the docs mentioned in the error message for other options:

Git can be configured to authenticate over HTTPS or to use SSH in place of HTTPS. To authenticate over HTTPS, you can add a line to the $HOME/.netrc file that git consults:

machine github.com login USERNAME password APIKEY

For GitHub accounts, the password can be a personal access token.

Git can also be configured to use SSH in place of HTTPS for URLs matching a given prefix. For example, to use SSH for all GitHub access, add these lines to your ~/.gitconfig:

insteadOf = https://github.com/

huangapple
  • 本文由 发表于 2023年4月12日 06:01:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75990435.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定