go get results in 'terminal prompts disabled' 错误 for github private repo

新手上路,请多包涵

我使用浏览器中的 Github UI 创建了私有存储库 examplesite/myprivaterepo。

然后我转到我的 go 目录(在桌面上)并克隆它:

 $ cd $GOPATH
$ go get github.com/examplesite/myprivaterepo

到目前为止,一切都很好。创建文件 scheduler.go,添加到 repo,并推送。

 $ vim scheduler.go
$ git add scheduler.go
$ git commit
$ git push

一切都好。但是,当我使用一台干净的笔记本电脑并尝试克隆存储库时,出现了一个错误:

 # Now on laptop, which doesn't yet know about the repo
$ cd $GOPATH
$ go get github.com/examplesite/myprivaterepo
# At this point it should ask for my user ID and password ,right? But it doesn't.
# Instead, this error occurs:
cd .; git clone https://github.com/examplesite/myprivaterepo /Users/tom/go/src/github.com/examplesite/myprivaterepo
Cloning into '/Users/tom/go/src/github.com/examplesite/myprivaterepo'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/examplesite/myprivaterepo: exit status 128

为什么我的笔记本电脑讨厌我自己的回购,我怎样才能让它接受它的命运?谢谢。

原文由 tomcam 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 580
2 个回答

go get 默认禁用“终端提示”。这可以通过设置 git 的环境变量来改变:

 env GIT_TERMINAL_PROMPT=1 go get github.com/examplesite/myprivaterepo

原文由 Shafreeck Sea 发布,翻译遵循 CC BY-SA 4.0 许可协议

我发现这非常有用,它解决了我的问题。此命令将允许您的 2FA 执行其操作(并省去输入用户名和密码的麻烦):

对于 Github:

 git config --global --add url."git@github.com:".insteadOf "https://github.com/"

对于 Gitlab:

 git config --global --add url."git@gitlab.com:".insteadOf "https://gitlab.com/"

资料来源: http ://albertech.blogspot.com/2016/11/fix-git-error-could-not-read-username.html

如果您不使用 2FA,您仍然可以使用 SSH,这会起作用。

结果 .gitconfig 将像:

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

原文由 Wylliam Judd 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题