Table of Contents
I just now came across the problem that I created a repository on a private GitLab instance for a Golang project and could not just use
go get ... to get it.
After a short Google search, I came across this StackOverflow question and thankfully it had a working answer.
The original StackOverflow question can be found here: StackOverflow - how do you use golang with a private gitlab repo?, the question was asked by User James Fremen.
I will quote the question and answer which worked here so it is sort of archived here.
The original question
GitLab is a free, open-source way to host private .git repositories but it does not seem to work with golang. When you create a project it generates a URL of the form:
> where: 220.127.116.11 is the IP address of the gitlab server private-developers is a user group which has access to the private repo > > Golang 1.2.1 doesn't seem to understand this syntax. > >```shell go get [email protected]:private-developers/project.git
package [email protected]/project.git: unrecognized import path “[email protected]/project.git”
> Is there a way to get this to work? > > thanks! Author of the question [James Fremen](https://stackoverflow.com/users/2904939/james-fremen) ## The answer that worked for me > Run this command: > >```shell git config --global url."[email protected]:".insteadOf "https://18.104.22.168/"
Assuming you have the correct privileges to
git clonethe repository, this will make go get work for all repos on server
I tested this to work with go version 1.6.2 and 1.8.
Author of the answer Rick Smith
Example for DNS names
So for example with dns names, it would be for a gitlab running at
git config --global url."[email protected]:".insteadOf "https://example.com/"
With that change, you can now successfully run
go get gitlab.example.com/example-user/example-project.