我使用浏览器中的Github UI创建了私有repo examplesite/myprivaterepo.
然后我去了我的go目录(在桌面上)并克隆了它:
$ cd $GOPATH
$ go get github.com/examplesite/myprivaterepo
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.创建文件scheduler.go,添加到repo,然后推送.
$ vim scheduler.go
$ git add scheduler.go
$ git commit
$ git push
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
为什么我的笔记本电脑讨厌我自己的回购,我怎么能让它接受它的命运呢?谢谢.
Wyl*_*udd 236
我发现这非常有帮助,它解决了我的问题.像Mike Graf一样,我使用2FA,但与Mike Graf不同,我不使用Mac.此命令将允许您的2FA执行其操作(并省去输入用户名和密码的麻烦):
--add
资料来源:http://albertech.blogspot.com/2016/11/fix-git-error-could-not-read-username.html
如果你没有使用2FA,你仍然可以使用SSH,这将有效.
编辑:--add按照slatunje的建议添加标志.
小智 142
go get默认禁用"终端提示".这可以通过设置git的环境变量来改变:
env GIT_TERMINAL_PROMPT=1 go get github.com/examplesite/myprivaterepo
Run Code Online (Sandbox Code Playgroud)
Muh*_*man 75
它抱怨是因为它需要使用ssh而不是,https但你的 git 仍然配置了 https。所以基本上就像前面提到的其他人一样,您需要启用提示或配置 git 来ssh代替.git 使用https。通过运行以下命令来执行此操作的简单方法:
git config --global --add url."git@github.com:".insteadOf "https://github.com/"
Run Code Online (Sandbox Code Playgroud)
或者,如果您已经在您的机器中使用sshwith git,您可以安全地编辑~/.gitconfig并在最底部添加以下行
注意:这涵盖了所有 SVC,源版本控制,这取决于你到底使用什么,github、gitlab、bitbucket)
# Enforce SSH
[url "ssh://git@github.com/"]
insteadOf = https://github.com/
[url "ssh://git@gitlab.com/"]
insteadOf = https://gitlab.com/
[url "ssh://git@bitbucket.org/"]
insteadOf = https://bitbucket.org/
Run Code Online (Sandbox Code Playgroud)
如果要禁用密码提示,则需要缓存密码。有关如何在 mac、windows 或 linux 上缓存您的 github 密码的更多信息,请访问此页面。
有关如何将 ssh 添加到您的 github 帐户的更多信息,请访问此页面。
此外,更重要的是,如果这是公司或您自己的私有存储库,您可能需要跳过对此类存储库使用代理或校验和数据库,以避免公开它们。
为此,您需要设置GOPRIVATE环境变量来控制 go 命令认为哪些模块是私有的(不公开),因此不应使用代理或校验和数据库。
该变量是以逗号分隔path.Match的模块路径前缀模式列表(与 Go 的语法相同)。例如,
export GOPRIVATE=*.corp.example.com,github.com/mycompany/*
Run Code Online (Sandbox Code Playgroud)
或者
go env -w GOPRIVATE=github.com/mycompany/*
Run Code Online (Sandbox Code Playgroud)
最后一件事不要忘记提到,您仍然可以配置go get为身份验证和获取https,您需要做的就是添加以下行$HOME/.netrc
machine github.com login USERNAME password APIKEY
Run Code Online (Sandbox Code Playgroud)
我希望这有助于社区并节省其他人的时间来快速解决所描述的问题。如果您需要更多支持或帮助,请随时发表评论。
Mik*_*raf 37
1st - go get将拒绝在命令行上进行身份验证.所以你需要在git中缓存凭据.因为我使用osx我可以使用osxkeychain凭证助手.
2对我来说,我启用了2FA,因此无法使用我的密码进行身份验证.相反,我必须生成一个个人访问令牌来代替密码.
git clone https://github.com/user/private_repo 仓库只是为了让它缓存密码 并使用你的github.com用户名作为用户名,并使用生成的个人访问令牌来获取密码.删除刚刚克隆的回购并重新测试以确保缓存信用 - git clone https://github.com/user/private_repo而这次并没有要求提供信用.
Vik*_*wal 30
添加这是您的 bash_profile:
export GOPRIVATE=github.com/your-organization/*
Run Code Online (Sandbox Code Playgroud)
然后运行:
git config --global --add url."git@github.com:".insteadOf "https://github.com/"
Run Code Online (Sandbox Code Playgroud)
EdH*_*EdH 13
如果你只是想go get快速工作,并继续你的工作......
只是出口 GIT_TERMINAL_PROMPT=1
$ export GIT_TERMINAL_PROMPT=1
$ go get [whatever]
Run Code Online (Sandbox Code Playgroud)
它现在将提示您为shell会话的其余部分提供用户/传递.将其放入您.profile或git上面的设置中,以获得更持久的解决方案.
从 1.13 开始,如果您已经使用 git 凭据配置了终端,但仍然面临此问题,那么您可以尝试设置GOPRIVATE环境变量。设置这个环境变量为我解决了这个问题。
export GOPRIVATE=github.com/{organizationName/userName of the package}/*
Run Code Online (Sandbox Code Playgroud)
虽然关于使用 GitHub 的 SSH 身份验证有很多答案,但问题与 go 模块的正确使用有关。为此,卢娜·洛夫古德在这里提供了正确的答案。
重申一下,默认情况下 Go 会尝试使用公共存储库来下载包。我们需要指定它使用 SSH 对私有存储库进行身份验证。为此,可以使用以下方法:
go env -w GOPRIVATE=github.com/{your-username}/{your-lib}
.
.
go mod vendor # this will now work for your private lib
Run Code Online (Sandbox Code Playgroud)
Glob 模式也适用,因此如果您有多个私有存储库,您可以添加
go env -w GOPRIVATE=github.com/{your-username}/*
Run Code Online (Sandbox Code Playgroud)
编辑:正确的措辞。
小智 5
如果使用此选项配置 gitconfig,稍后克隆 GitHub 的其他存储库时会出现问题
git config --global --add url. "Git@github.com". Instead, "https://github.com/"
Run Code Online (Sandbox Code Playgroud)
相反,我建议您使用此选项
echo "export GIT_TERMINAL_PROMPT=1" >> ~/.bashrc || ~/.zshrc
Run Code Online (Sandbox Code Playgroud)
并且不要忘记从您的私人存储库生成访问令牌。当提示输入密码时,只需粘贴访问令牌即可。快乐的克隆:)
| 归档时间: |
|
| 查看次数: |
129343 次 |
| 最近记录: |