Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Go Get' Private Repo from Bitbucket

Tags:

git

bitbucket

go

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!

like image 729
BeeAdmin Avatar asked Jul 29 '16 22:07

BeeAdmin


People also ask

How do I access private Bitbucket repository?

A private Git repository on Bitbucket can be accessed using either SSH or HTTPS. The preferred method is to always use SSH and a SSH key pair. Only use HTTPS if you have no choice.

Is Bitbucket repo private?

When you create a Bitbucket Cloud repository, you specify whether it's private or public, but you can also change this setting at any time. If your repository is public, anyone can access and fork it. If your repository is private, you can specify who exactly can access your repository and whether they can fork it.

Does Bitbucket offer free private repos?

Yes! Bitbucket is free for individuals and small teams with up to 5 users, with unlimited public and private repositories. You also get 1 GB file storage for LFS and 50 build minutes to get started with Pipelines. You share build minutes and storage with all users in your workspace.


2 Answers

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

like image 119
Ammar Bandukwala Avatar answered Sep 29 '22 16:09

Ammar Bandukwala


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

like image 33
naoko Avatar answered Sep 29 '22 14:09

naoko