“去获取”私有存储库的正确方法是什么?

新手上路,请多包涵

我正在寻找获得 $ go get 使用私有存储库的方法,经过多次谷歌尝试。

第一次尝试:

 $ go get -v gitlab.com/secmask/awserver-go
Fetching https://gitlab.com/secmask/awserver-go?go-get=1
https fetch failed.
Fetching http://gitlab.com/secmask/awserver-go?go-get=1
Parsing meta tags from http://gitlab.com/secmask/awserver-go?go-get=1 (status code 200)
import "gitlab.com/secmask/awserver-go": parse http://gitlab.com/secmask/awserver-go?go-get=1: no go-import meta tags
package gitlab.com/secmask/awserver-go: unrecognized import path "gitlab.com/secmask/awserver-go

是的,它没有看到元标记,因为我不知道如何提供登录信息。

第二次尝试:

关注 https://gist.github.com/shurcooL/6927554 。将配置添加到 .gitconfig。

 [url "ssh://git@gitlab.com/"]
    insteadOf = https://gitlab.com/
$ go get -v gitlab.com/secmask/awserver-go --> not work
$ go get -v gitlab.com/secmask/awserver-go.git --> work but I got src/gitlab.com/secmask/awserer-go.git

是的,它可以工作,但是 .git 带有我的项目名称的扩展名,我可以将它重命名为原始名称,但每次都这样做 $ go get 不太好,还有别的办法吗?

原文由 secmask 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 921
1 个回答

您需要配置一件事。该示例基于 GitHub,但这不应改变流程:

 $ git config --global url.git@github.com:.insteadOf https://github.com/
$ cat ~/.gitconfig
[url "git@github.com:"]
    insteadOf = https://github.com/
$ go get github.com/private/repo

为了让 Go 模块工作(使用 Go 1.11 或更新版本),您还需要设置 GOPRIVATE 变量,以避免使用公共服务器获取代码:

 export GOPRIVATE=github.com/private/repo

原文由 JulienD 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题