我正在寻找让 $ go get
使用私有(private)存储库的方法,经过多次谷歌尝试。
第一次尝试:
$ 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
不是很好,是吗另一种方式?
最佳答案
您需要配置一件事。该示例基于 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
变量,以避免使用公共(public)服务器获取代码:
export GOPRIVATE=github.com/private/repo
关于git - "go get"私有(private)存储库的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56217576/