在我的Apple MAC上,从GitHub获取私有存储库的URL无法正常工作。

huangapple go评论80阅读模式
英文:

go get url from github on my Apple MAC is not working on a private repository in company

问题

我正在使用苹果MAC笔记本电脑,go get命令无法工作。
我可以正常访问git,可以进行git克隆、git提交和git推送。为什么go get命令不能工作?

temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
	ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
	fatal: Could not read from remote repository.
	
	Please make sure you have the correct access rights
	and the repository exists.
temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
	ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
	fatal: Could not read from remote repository.
	
	Please make sure you have the correct access rights
	and the repository exists.

这个错误提示表明在执行go get命令时,无法解析主机名github.com:MYCOMPANY。请确保你的网络连接正常,并且你有正确的访问权限以及仓库存在。

英文:

I'm on a Apple MAC Laptop, go get command is not working.
I have normal git access, I can git clone and git commit and git push. Why does this go get command not work?

temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
	ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
	fatal: Could not read from remote repository.
	
	Please make sure you have the correct access rights
	and the repository exists.
temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
	ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
	fatal: Could not read from remote repository.
	
	Please make sure you have the correct access rights
	and the repository exists.

答案1

得分: 4

这是对我有效的方法,基于 @elulcao 的建议:

go env -w GOPRIVATE=github.com/COMPANYNAME
git config --global --add url."git@github.com:".insteadOf "https://github.com/"

然后我可以在项目的 git 文件夹中执行以下命令:

go mod download

或者使用 go get 命令。

英文:

This is what works for me, based on @elulcao

go env -w GOPRIVATE=github.com/COMPANYNAME
git config --global --add url."git@github.com:".insteadOf "https://github.com/"

Then I can do

go mod download

In the projects git folder or go get

答案2

得分: -1

“go get”默认不支持私有仓库,它只支持公共仓库。

如果你想获取私有仓库,请参考这个链接:link

英文:

'go get' by default does not support private repositories. It only supports public repos.

If you want to get private repos please refer to this link

huangapple
  • 本文由 发表于 2022年1月3日 12:50:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/70561783.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定