英文:
'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/<account_name>
)
And also execute:
git config --global url."ssh://git@altssh.work-bitbucket.org:443/<account_name>".insteadOf "https://bitbucket.org/<account_name>"
Note about the 'work' prefix
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论