首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GOPRIVATE和go mod私有git存储库

GOPRIVATE和go mod私有git存储库
EN

Stack Overflow用户
提问于 2022-09-08 07:46:57
回答 1查看 231关注 0票数 1

尝试在我以前的组织中设置go mod tidygo mod download我要做的就是只是设置GOPRIVATE,将ssh公钥添加到github/bitbucket/gitlab,将IdentityFile用于连接自定义域的.ssh/config设置为.ssh/config,然后设置.gitconfig,如下所示:

代码语言:javascript
运行
复制
go env -w GOPRIVATE="github.com/xxx/*"

# .gitconfig
[url "git@github.com:/xxx/"]
     insteadOf = https://github.com/xxx/

但是另一个组织不能工作(使用bitbucket),尝试使用auth键或ssh在执行go mod tidy/download时仍然有问题

代码语言:javascript
运行
复制
go env -w GOPRIVATE="bitbucket.xxx/*,bitbucket.xxx:9022/*" 
# 9022 is their ssh port used for cloning a repo

# .gitconfig
#[url "https://:ACCTOKEN@bitbucket.xxx/"] # ACCTOKEN is my access token
[url "ssh://git@bitbucket.xxx:9022/"]
     insteadOf = https://bitbucket.xxx/

两者都没有工作,如果没有.gitconfig,就会显示错误:

代码语言:javascript
运行
复制
go: bitbucket.xxx/yyy/zzz/aaa/bbb@v0.0.0-20220728131025-25f2fba58852: invalid version: git ls-remote -q origin in /home/asd/go/pkg/mod/cache/vcs/be703481c10c8d59451fefcffbf5e7341aab5edf1c25acbaa8356c8fbeef42d2: exit status 128:
        fatal: could not read Username for 'https://bitbucket.xxx': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

如果在.gitconfig上使用访问令牌,错误是:

代码语言:javascript
运行
复制
go: bitbucket.xxx/yyy/zzz/aaa/bbb@v0.0.0-20220728131025-25f2fba58852: invalid version: git ls-remote -q origin in /home/asd/go/pkg/mod/cache/vcs/be703481c10c8d59451fefcffbf5e7341aab5edf1c25acbaa8356c8fbeef42d2: exit status 128:
        fatal: Authentication failed for 'https://bitbucket.xxx/scm/yyy/zzz.git/'

^无法正确使用此、密码或访问令牌,因此总是被拒绝。

如果在.gitconfig上使用ssh,错误是:

代码语言:javascript
运行
复制
go: bitbucket.xxx/yyy/zzz/aaa/bbb@v0.0.0-20220728131025-25f2fba58852: invalid version: git ls-remote -q origin in /home/asd/go/pkg/mod/cache/vcs/be703481c10c8d59451fefcffbf5e7341aab5edf1c25acbaa8356c8fbeef42d2: exit status 128:
        Repository not found
        The requested repository does not exist, or you do not have permission to access it.
        fatal: Could not read from remote repository.
        
        Please make sure you have the correct access rights
        and the repository exists.

我可以正常使用这个git clone ssh://git@bitbucket.xxx:9022/yyy/zzz.git,但如果使用go mod (或者使用IntelliJ),则失败。

xxx是组织域名,组织强制对ssh密钥使用密码。

我漏掉了什么吗?或者如何强制go mod使用ssh而不是https来克隆/下载?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-08 07:56:59

不过,.gitconfig错了,它应该是这样的:

代码语言:javascript
运行
复制
[url "ssh://git@bitbucket.xxx:9022/"]
    insteadOf = https://bitbucket.xxx/scm/

在我的例子中,后缀中有scm

现在可以正确的git clone https://bitbucket.xxx/scm/yyy/zzz.git,与go mod也工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73645428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档