我正在寻找获得$ 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-config,因此我的用户可以使用正确的凭证和密钥自动登录。

首先,我需要生成一个密钥对

ssh-keygen -t rsa -b 4096 -C "my@email.here"

并保存到例如~/.ssh/id_my_domain。请注意,这也是我连接到我的Github帐户的对口令(私有和公共),所以我的存储在~/.ssh/id_github_com。

然后我创建(或修改)了一个名为~/的文件。Ssh /config有一个条目:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_github_com

在另一个服务器上,“ssh-url”是admin@domain.com:username/private-repo.git,这个服务器的条目应该是:

Host domain.com
    HostName domain.com
    User admin
    IdentityFile ~/.ssh/id_domain_com

澄清一下,您需要确保正确设置了User、Host和HostName。

现在我可以浏览到go路径,然后去get <package>,例如去get main文件main/main。Go包含包(来自上一个例子)domain.com:username/private-repo.git。

其他回答

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

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

正确的方法是手动将存储库放在正确的位置。一旦有了存储库,您可以使用go get -u来更新包,然后使用install来安装它。一个名为

github.com/secmask/awserver-go

进入

$GOPATH/src/github.com/secmask/awserver-go

您键入的命令是:

cd $GOPATH/src/github.com/secmask
git clone git@github.com:secmask/awserver-go.git

我已经创建了一个特定于用户的ssh-config,因此我的用户可以使用正确的凭证和密钥自动登录。

首先,我需要生成一个密钥对

ssh-keygen -t rsa -b 4096 -C "my@email.here"

并保存到例如~/.ssh/id_my_domain。请注意,这也是我连接到我的Github帐户的对口令(私有和公共),所以我的存储在~/.ssh/id_github_com。

然后我创建(或修改)了一个名为~/的文件。Ssh /config有一个条目:

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_github_com

在另一个服务器上,“ssh-url”是admin@domain.com:username/private-repo.git,这个服务器的条目应该是:

Host domain.com
    HostName domain.com
    User admin
    IdentityFile ~/.ssh/id_domain_com

澄清一下,您需要确保正确设置了User、Host和HostName。

现在我可以浏览到go路径,然后去get <package>,例如去get main文件main/main。Go包含包(来自上一个例子)domain.com:username/private-repo.git。

我有一个问题,从我们公司的gitlab使用私人存储库。 我花了几分钟试图找到解决办法。我找到了这个:

你需要获得一个私人令牌: https://gitlab.mycompany.com/profile/account 配置你的git添加额外的头与你的私有令牌: $ git配置——global http。"PRIVATE-TOKEN: YOUR_PRIVATE_TOKEN" 配置你的git将请求从http转换为ssh: $ git配置——全局url."git@gitlab.mycompany.com:". insteadof "https://gitlab.mycompany.com/" 最后你可以正常使用你的go get: $ go get gitlab.com/company/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文档中的元标签”。