git - "go get"私有(private)存储库的正确方法是什么?

标签 git go

我正在寻找获取$ 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/62083787/

相关文章:

git svn rebase 总是与我自己的提交冲突

java - 内存中有文件系统库吗?

pointers - 测试嵌套结构中的 nil 值

Git p4 merge pull 请求

linux - 在 linux 和 Windows 环境中共享时, Material 设计图标(如 "\f222")会发生变化

git - 忽略 git 目录

git - 无法推送到 Bitbucket 上的 Git 存储库

go - 如何在延迟函数中延迟执行参数

windows - 转到 : Raw winsock

go - 如何在 Go 中将 "type"用作结构属性?