Reputation: 551
So basically, I have an Openshift Project that on Git push, downloads all libraries with 'Go get' and builds the project on-the-fly and so, I have some code I don't want people to see from my own library, and for it to compile properly, the code needs to be taken from github.com or another repo, so I created a private bitbucket.org repo, now, as a public repo it works fine, but when I try to 'Go Get' from my private repo, it gives me 'Forbidden 403'
How can I avoid this occurency? Thank you for reading and have a nice day!
Upvotes: 43
Views: 52740
Reputation: 11
For anyone coming here after trying all of the above (and getting a 404 instead of a 403) this is because BB changed the response code from 403 to 404 when you're fetching a private repo. Golang has a fallback to HTTP when the repo cannot be resolved through SSH. This was fixed in golang version 1.16+.
Upvotes: 1
Reputation: 5216
Adition to setting git config
described by others, I had to set GOPRIVATE
.
Step 1. git config --global url."git@bitbucket.<YOUR-COMPANY>".insteadOf "https://bitbucket.org/<YOUR-COMPANY>"
Step 2. export GOPRIVATE=bitbucket.org/<YOUR-COMPANY>
the GOPRIAVTE
is documented here: https://golang.org/cmd/go/#hdr-Module_configuration_for_non_public_modules
Upvotes: 20
Reputation: 320
Ammar Bandukwala's answer is correct, but if you find yourself behind a firewall with SSH outgoing port (22) closed, you can use SSH over HTTPS port (443) instead:
git config --global url."ssh://[email protected]:443/<account_name>".insteadOf "https://bitbucket.org/<account_name>"
Upvotes: 2
Reputation: 1582
go get
uses git
internally. The following one liners will make git
and consequently go get
clone your package via SSH.
Github:
git config --global url."[email protected]:".insteadOf "https://github.com/"
BitBucket:
git config --global url."[email protected]:".insteadOf "https://bitbucket.org/"
Upvotes: 84