去github私人回购的'terminal提示禁用'错误的结果

我从浏览器中使用Github UI创build了私人回购examplesite / myprivaterepo。

然后,我去我的去目录(在桌面上)并克隆它:

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

到现在为止还挺好。 创build文件scheduler.go,添加到回购,并推送。

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

Everythng的确定。 但是当我去一个干净的笔记本电脑,并试图克隆回购,我得到一个错误:

 # 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 

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

去获取禁用“terminal提示”默认情况下。 这可以通过设置git的env来改变:

 env GIT_TERMINAL_PROMPT=1 go get xxxx 

第一 – go get将拒绝在命令行进行身份validation。 所以你需要在git中caching凭据。 因为我使用osx我可以使用osxkeychain凭证助手。

第二对我来说,我有2FA启用,因此不能使用我的密码来validation。 相反,我必须生成一个个人访问令牌来代替密码。

  1. 设置osxkeychain凭证助手https://help.github.com/articles/caching-your-github-password-in-git/
  2. 如果使用TFA而不是使用密码,请生成个人访问令牌https://github.com/settings/tokens
  3. git克隆一个私人回购只是为了caching密码git clone https://github.com/user/private_repo并使用你的github.com用户名和用户名和生成的个人访问令牌的密码。
  4. 删除刚刚克隆的回购和重新testing,以确保信用被caching – git clone https://github.com/user/private_repo ,这次没有要求信用。

    1. 去获取将与个人访问令牌可以访问的任何回购一起工作。 您可能需要重复其他帐户/令牌的步骤,因为权限会有所不同。

我发现这非常有帮助,它解决了我的问题。 就像麦克·格拉夫(Mike Graf)一样,我使用的是2FA,但与迈克·格拉夫(Mike Graf)不同, 这个命令将允许你的2FA做它的事情(并且节省你input用户名和密码的麻烦):

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

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

如果你不使用2FA,你仍然可以使用SSH,这将工作。

编辑:添加 – 标志由slatunjebuild议。

如果你只想go get真正的工作,并与你的工作一起移动…

只要输出GIT_TERMINAL_PROMPT=1

 $ export GIT_TERMINAL_PROMPT=1 $ go get [whatever] 

它现在会提示你input一个用户名/密码进行剩下的shell会话。 把它放在你的.profile或者像上面那样设置git ,以获得更持久的解决scheme。