Sysadmin Garden of Eden

Golang: go get from GitLab

Table of Contents
  1. 1. The original question
  2. 2. The answer that worked for me
    1. 2.1. Example for DNS names
  3. 3. Summary

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.

Note: 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:

[email protected]:private-developers/project.git

where: 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.

go get [email protected]:private-developers/project.git

results in:

package [email protected]/project.git: unrecognized import path "[email protected]/project.git"

Is there a way to get this to work?


Author of the question James Fremen

The answer that worked for me

Run this command:

git config --global url."[email protected]:".insteadOf ""

Assuming you have the correct privileges to git clone the 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 gitlab.example.com.

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.

Have Fun!