git - go get results in 'terminal prompts disabled' error for github private repo

标签 git go

我在浏览器中使用 Github UI 创建了私有(private) repo 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

一切正常。但是当我去一台干净的笔记本电脑并尝试克隆 repo 时,我收到了一个错误:

# 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

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

最佳答案

我发现这非常有用,它解决了我的问题。此命令将允许您的 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/

关于git - go get results in 'terminal prompts disabled' error for github private repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32232655/

相关文章:

go - mplayer 无法从 golang 获取标准输入流

go - 事件源golang : how to detect client disconnection?

opencv - 寻找拥有 GOCV 的人

bash - 为 Go 编程语言设置 vim 自动完成

go - 将 gomake/gotest 用于具有外部依赖项的包

git - 如何在 VS Code 中只提交跟踪的文件?

Git:自动从存储库中 pull ?

git - 不清楚 git Push 如何影响远程分支

git - 如果rstudio如何从git选项卡中获取文件

git - 使子模块中的文件只读