登录
首页 >  Golang >  Go问答

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

来源:stackoverflow

时间:2024-04-17 14:57:34 283浏览 收藏

目前golang学习网上已经有很多关于Golang的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《无法读取“https://github.com”的用户名:Windows 上禁用终端提示》,也希望能帮助到大家,如果阅读完后真的对你学习Golang有帮助,欢迎动动手指,评论留言并分享~

问题内容

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

server response:
not found: github.com/..../[email protected]: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/168bff8af96cdfac9cbe3ad64f7753732f8a19d99f7f1e897f19371e1ea453d9: 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.

我尝试导出 set git_terminal_prompt=1 但没有任何反应,发出相同的错误。对于 go 1.13,有什么办法 go get 会在 windows 上忽略此变量的值吗?


正确答案


尝试为 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 还可以配置为使用 ssh 代替 https 来处理与给定前缀匹配的 url。例如,要使用 ssh 进行所有 github 访问,请将这些行添加到 ~/.gitconfig

[url "ssh://[email protected]/"]
    insteadOf = https://github.com/

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《无法读取“https://github.com”的用户名:Windows 上禁用终端提示》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>