2

#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/?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
haalcala
  • 63
  • 5
  • 1
    Have you tried setting a [`url..insteadOf`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf) replace rule on your local machine ? – LeGEC Jul 05 '21 at 11:26
  • 1
    the more go-ish solution is probably to set up a corporate goproxy (see [`GOPROXY portocol` section in the docs](https://golang.org/ref/mod#goproxy-protocol)), but I don't know of a standard implementation for such a proxy. – LeGEC Jul 05 '21 at 11:32
  • 1
    perhaps https://github.com/goproxy/goproxy ? – LeGEC Jul 05 '21 at 11:34
  • 1
    try following these 2 steps https://stackoverflow.com/a/62558193/10461720 – D.C. Joo Jul 05 '21 at 23:41

1 Answers1

2

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>/" 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

haalcala
  • 63
  • 5