我从浏览器中使用Github UI创建了私人回购示例站点/myprivaterepo。

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

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

到目前为止一切顺利。创建文件调度程序。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

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


当前回答

首先,go get将拒绝在命令行上进行身份验证。所以你需要在git中缓存凭证。因为我使用osx,我可以使用osxkeychain凭据助手。

对我来说,我已经启用了2FA,因此不能使用我的密码进行认证。相反,我必须生成一个个人访问令牌来代替密码。

setup osxkeychain credential helper https://help.github.com/articles/caching-your-github-password-in-git/ If using TFA instead of using your password, generate a personal access token with repo scope https://github.com/settings/tokens git clone a private repo just to make it cache the password git clone https://github.com/user/private_repo and used your github.com username for username and the generated personal access token for password. Removed the just cloned repo and retest to ensure creds were cached -- git clone https://github.com/user/private_repo and this time wasnt asked for creds. go get will work with any repos that the personal access token can access. You may have to repeat the steps with other accounts / tokens as permissions vary.

其他回答

首先,go get将拒绝在命令行上进行身份验证。所以你需要在git中缓存凭证。因为我使用osx,我可以使用osxkeychain凭据助手。

对我来说,我已经启用了2FA,因此不能使用我的密码进行认证。相反,我必须生成一个个人访问令牌来代替密码。

setup osxkeychain credential helper https://help.github.com/articles/caching-your-github-password-in-git/ If using TFA instead of using your password, generate a personal access token with repo scope https://github.com/settings/tokens git clone a private repo just to make it cache the password git clone https://github.com/user/private_repo and used your github.com username for username and the generated personal access token for password. Removed the just cloned repo and retest to ensure creds were cached -- git clone https://github.com/user/private_repo and this time wasnt asked for creds. go get will work with any repos that the personal access token can access. You may have to repeat the steps with other accounts / tokens as permissions vary.

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

我试着添加这个命令

export GOPRIVATE = github。中银协(private_reponame) *

这对我很有效

这是你的bash_profile:

export GOPRIVATE=github.com/your-organization/*

然后运行:

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

在更改我的凭据后,我面临这个错误终端提示被禁用,迦太基未能更新依赖项并在终端上显示此错误。

我只是做了简单的以下步骤,它开始工作…

从钥匙串访问中删除旧凭据 试图在不同的位置克隆相同的回购。 它要求设置凭据(用户名+密码)。 然后迦太基更新像以前一样工作。