How to use GoLang with a private Gitlab repo?

go get gitlab private repo
go get private repository
golang gitlab
go get gitlab subgroup
go get private repo docker
golang could not read from remote repository
go get 410 gone
cannot find module providing package private repo

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:



  • 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 git@

results in:

package git@ unrecognized import path "git@"

Is there a way to get this to work?

This issue is now resolved in Gitlab 8.* but is still unintuitive. The most difficult challenge indeed is go get and the following steps will allow you to overcome those:

  1. Create an SSH key pair. Be sure to not overwrite an existing pair that is by default saved in ~/.ssh/.

    ssh-keygen -t rsa -b 4096
  2. Create a new Secret Variable in your Gitlab project. Use SSH_PRIVATE_KEY as Key and the content of your private key as Value.

  3. Modify your .gitlab-ci.yml with a before_script.

      # install ssh-agent if not already installed
      - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
      # run ssh-agent
      - eval $(ssh-agent -s)
      # add the SSH key stored in SSH_PRIVATE_KEY
      - ssh-add <(echo "$SSH_PRIVATE_KEY")
      # for Docker builds disable host key checking
      - mkdir -p ~/.ssh
      - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  4. Add the public key from the key pair created in step 1 as a Deploy Key in the project that you need to go get.

How to use Go with a private GitLab repo, The problem I get is that my projects are hosted on a private gitlab server, I used the classic git replacement technique to have *go get* use ssh instead of https  Private Repositories. Under the hood, Go is using Git to pull the specified versions of your dependencies. So, the git configuration for wherever Go is running (eg. a Docker container or your laptop) has to have the appropriate credentials to access any private repositories. Fortunately for us, there’s a git command for that.

Run this command:

git config --global url."git@".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 with go version 1.6.2, 1.8, and 1.9.1.

Go module with private gitlab repos : golang, 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  How to install dependency from the private repository with a self-signed certificate? The gitlab isn't available by http, https is self-signed, and we can't change it or its settings - it belongs to another company, we just work in this

If go get can't fetch the repo, you can always do the initial clone with git directly:

git clone git@gitlab:private-developers/project.git $GOPATH/src/gitlab/private-developers/project

The tools will then work normally, expect for go get -u which will require the -f flag because the git remote doesn't match the canonical import path.

Golang: go get from GitLab, you configure your development environment to allow Go Modules to work with private Git repositories. What is the best IDE for developing in Golang? Under the hood, Go is using Git to pull the specified versions of your dependencies. What version of Go are you using (go version)? $ go version go version go1.14.2 darwin/amd64 Does this issue reproduce with the latest release? Yes What operating system and processor architecture are you using (go env)? go env Output$ g

Gitlab does support go get natively.

go get will issue an http request to the url you provide and look for meta tags that point to the exact source control path.

For my gitlab installation this is For you I assume this would be

Unfortunately it only appears to give the http scm path, not the ssh path, so I had to enter my credentials to clone. You can easily fiddle with the remote in your local repository after it clones if you want to update to the ssh url.

You can test the url by poking and viewing source and looking for the meta tag.

Go Modules with Private Git Repositories, I've some project stored separated into 3 git-host providers: Github, software engineer, I use both in Gitlab and Bitbucket for the private… So, a few days ago​, I'm trying to create a project of Golang and stored it in Gitlab. @hxzhao527 @oiooj Thx,I think the reason is my private repo which isn't used TLS. And I used another solution by setting GOPRIVATE env to exclude my private repo,goproxy is only for public packages.I think it's a good solution for me.What I need to wait for is Go1.13 released. I hope my experience will be helpful to this discussion.

For the record, this works outside of go using gitlab 7.3.2 and, as JimB has observed, can be used as a workaround. I find that i do get prompted for username/password, even though an SSH key is registered with gitlab:

git clone

Alternatively i can use the SSH equivalent which, since i have an SSH key registered with gitlab, avoids the prompts:

git clone git@

Neither works with go currently. A fix may be in 7.9 but i haven't had a chance to test it: upcoming bugfix

Today I Learned, Import private go modules from gitlab repositories. golang. Spread the love with git over https, while we extensively use ssh for all communication with private repositories (and I would encourage you to do the same). Can anyone with more knowledge of golang than me confirm this? My key assumption is that once go decides to use modules, all dependencies must be modules and the gopath becomes somewhat irrelevant, except as a cache (for downloaded modules). Is this correct? If this is true, we need to use a private gitlab (in our case) repository on the path.

Import private go modules from gitlab repositories, How to `go get` private repos using SSH key auth instead of password auth. server. #Why does "go get" use HTTPS when cloning a  Then it tries to check if a private repo is git or hg (as per issue #5375) , first using git, that will also resolve in 403 - if global git config does not include , Yet, this would not be enough without cached credentials on cred manager OR ssh key configured for your bitbucket user.

How to `go get` private repos using SSH key auth , We want to use it to create private libraries. So I wrote a simple test to check I can import submodules: // File: main.go package main import  It looks like there's not a straightforward solution for HTTPS-based cloning regarding GitLab. Therefore if you want a SSH-based cloning, you should take account these three forthcoming steps: Create properly an SSH key using your email used to sign up. I would use the default filename to key for Windows. Don't forget to introduce a password!

cmd/go: modules do not work with , I am having a struggle using go.mod and private gitlab repository. When I try to build my project go tries to download my repo and gets error 410 Gone. you want that the packages are not downloaded from . Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

  • that's not how go get works, it uses import paths, not direct scm uris. Does your gitlab have https git access (like github)?
  • I'm not sure. It was installed via this procedure: . Is there a way i can tell?
  • I'm not really familiar with gitlab, but I know they added support for go get on public projects: Worst case you can always just do the initial clone of the repo into your GOPATH manually
  • regrettably i have to use a private repo for this. I am using the 'worst case' for now :).
  • Possible duplicate of What's the proper way to "go get" a private repository?
  • regrettably i can't verify that this works as I'm not currently using gitlab. If someone can verify this i'll mark it as the answer.
  • Thanks @JamesFremen, I don't know that anyone will jump on it but I've had several people ask me about it and it seems to work well.
  • This worked for me after I added one more line to the before_script section: - git config --global url."".insteadOf ""
  • yes, i think this is the workaround i'm currently using.
  • I've posted an answer as well.. it seems like a fix is in gitlab 7.9.
  • thanks for all the help.. hopefully this is working smoothly in the near future
  • Just a heads up. Although the bug was closed, the issue still remains.
  • @JamesFreman I'm on gitlab 8.2, and still getting http urls. Any idea what is going on?
  • He is talking about gitlab, not github. Gitlab is an open source project for private repository hosting.