我正在寻找获得$ go与私人存储库工作的方法,经过许多谷歌尝试。

第一次尝试:

$ 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。将config添加到.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不太好,有没有其他方法?


当前回答

如果你已经使用SSH得到git, Ammar Bandukwala的回答是一个简单的解决方案:


$ go get内部使用git。下面的一行代码将使git和$ go get通过SSH克隆你的包。

Github:

$ git config --global url."git@github.com:".insteadOf "https://github.com/"

BitBucket都:

$ git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"

其他回答

我偶然发现了.netrc,并发现它与此相关。

创建一个包含以下内容的文件~/.netrc:

machine github.com
    login <github username>
    password <github password or Personal access tokens >

完成了!

此外,对于最新的GO版本,您可能需要将其添加到环境变量GOPRIVATE=github.com (我已经把它添加到我的。zshrc)

netrc还使我的开发环境设置更好,因为我个人的github访问HTTPS现在已配置为跨机器使用(就像我的SSH配置)。

生成GitHub个人访问令牌:https://github.com/settings/tokens

请参阅这个答案,了解它在Windows上与Git的具体使用

参考:netrc手册页


如果您希望坚持使用SSH身份验证,那么可以屏蔽请求以强制使用SSH

git配置——全局url."git@github.com:". insteadof "https://github.com/"


更多设置git访问的方法:https://gist.github.com/technoweenie/1072829#gistcomment-2979908

你有一个东西要配置。这个例子是基于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

看起来像是GitLab的5769期。

在GitLab中,由于存储库总是以.git结尾,我必须在存储库名称的末尾指定.git以使其正常工作,例如: 进口“example.org/myuser/mygorepo.git” 和: $ go get example.org/myuser/mygorepo.git 看起来GitHub通过添加“。git”解决了这个问题。

它应该在“增加对Go的存储库检索的支持”中得到解决。#5958”,前提是正确的元标记就位。 尽管Go本身仍然存在一个问题:“cmd/ Go: Go get无法发现HTML5文档中的元标签”。

如果你已经使用SSH得到git, Ammar Bandukwala的回答是一个简单的解决方案:


$ go get内部使用git。下面的一行代码将使git和$ go get通过SSH克隆你的包。

Github:

$ git config --global url."git@github.com:".insteadOf "https://github.com/"

BitBucket都:

$ git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"

在尝试了多种解决方案后,我的问题仍然存在。设置~/.netrc和SSH配置文件后的最终解决方案是在~/.bash_profile中添加以下行

出口GOPRIVATE = " github.com/(组织)”