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:

git@1.2.3.4:private-developers/project.git

where:

  • 1.2.3.4 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@1.2.3.4:private-developers/project.git

results in:

package git@23.251.148.129/project.git: unrecognized import path "git@1.2.3.4/project.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.

    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@1.2.3.4:".insteadOf "https://1.2.3.4/"

Assuming you have the correct privileges to git clone the repository, this will make go get work for all repos on server 1.2.3.4.

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 mygitlabdomain.com/myProject/myRepo. For you I assume this would be 1.2.3.4/private-developers/project.

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 http://1.2.3.4:private-developers/project?go-get=1 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 http://1.2.3.4/private-developers/project.git

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

git clone git@1.2.3.4:private-developers/project.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. http://golang.org/doc/faq #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 user.name , user.email. 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 Gitlab.com/Company/Team/Repo , 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 proxy.golang.org . 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.

Comments
  • 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: cloud.google.com/solutions/gitlab . 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: github.com/gitlabhq/gitlabhq/pull/5958. 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."git@gitlab.com:".insteadOf "https://gitlab.com/"
  • 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.