从Bitbucket上使用两个不同的Bitbucket账户进行”go get”操作。

huangapple go评论82阅读模式
英文:

'go get' from bitbucket with two different bitbucket account

问题

#1 我按照一些文章的指导成功地使用两个不同的SSH密钥访问GitHub或Bitbucket,当我执行git clone ...命令时一切正常。所以,我可以执行git clone git://git@github.com/...git clone git://git@mycompany-bitbucket.org/...而没有任何问题。

#2 我还按照一些文章的指导使用私有仓库。

然而,如果我将这两篇文章(#1和#2)结合起来,go get ...命令将始终使用https://api.bitbucket.org/2.0/repositories/...。所以,有没有办法强制go get ...使用类似于https://api.mycompany-bitbucket.org/2.0/repositories/的地址?

英文:

#1 I followed some articles on how to access github or bitbucket with two different ssh keys, and it works fine when I do a git clone .... So, I can do a git clone git://git@github.com/... and git clone git://git@mycompany-bitbucket.org/... without any problem.

#2 I also followed some article on how to use private repository

However, if I combine the two articles (#1 and #2), go get ... will always use the https://api.bitbucket.org/2.0/repositories/... . So, is there a way to force go get ... to use something like https://api.mycompany-bitbucket.org/2.0/repositories/?

答案1

得分: 2

感谢大家的回复。经过一些测试和调试,我找到了确定的步骤:

在 ~/.ssh/config 文件中:

# 工作 Bitbucket 账户
Host work-bitbucket.org
 HostName bitbucket.org
 User git
 AddKeysToAgent yes
 IdentityFile ~/.ssh/id_dsa-work

# 工作 Bitbucket 账户
Host altssh.work-bitbucket.org
 HostName altssh.bitbucket.org
 User git
 AddKeysToAgent yes
 IdentityFile ~/.ssh/id_dsa-work

work-bitbucket.org 允许你执行 git clone git@work-bitbucket.org/<account_name>/<repo> 并使用自定义的 SSH 密钥。

altssh.work-bitbucket.org 满足 go get ... 的要求(使用 export GOPRIVATE=bitbucket.org/<account_name>)。

还需要执行以下命令:

git config --global url."ssh://git@altssh.work-bitbucket.org:443/<account_name>".insteadOf "https://bitbucket.org/<account_name>"

关于 work 前缀的说明。

英文:

Thank you all for your responses. After doing some testing and tinkering, I found out this definitive steps:

In ~/.ssh/config:

# Work Bitbucket account
Host work-bitbucket.org
 HostName bitbucket.org
 User git
 AddKeysToAgent yes
 IdentityFile ~/.ssh/id_dsa-work

# Work Bitbucket account
Host altssh.work-bitbucket.org
 HostName altssh.bitbucket.org
 User git
 AddKeysToAgent yes
 IdentityFile ~/.ssh/id_dsa-work

The work-bitbucket.org allows you to do 'git clone git@work-bitbucket.org/<account_name>/<repo>" and use a custom ssh key

The altssh.work-bitbucket.org satisfies the requirement for go get ... (with export GOPRIVATE=bitbucket.org/&lt;account_name&gt;)

And also execute:

git config --global url.&quot;ssh://git@altssh.work-bitbucket.org:443/&lt;account_name&gt;&quot;.insteadOf &quot;https://bitbucket.org/&lt;account_name&gt;&quot;

Note about the 'work' prefix

huangapple
  • 本文由 发表于 2021年7月5日 17:55:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/68254076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定