2

I want to use go get to get a package located in a private GitLab repository. My go version is go1.15.4 darwin/amd64. And the current directory has a go.mod file.

When I run go get -v git.xxx.com/path-to/package@v0.0.3, It shows

get "git.xxx.com/path-to/package": found meta tag get.metaImport{Prefix:"git.xxx.com/path-to/package", VCS:"git", RepoRoot:"https://git.xxx.com/path-to/package.git"} at //git.xxx.com/path-to/package?go-get=1
get "git.xxx.com/path-to": found meta tag get.metaImport{Prefix:"git.xxx.com/path-to", VCS:"git", RepoRoot:"https://git.xxx.com/path-to.git"} at //git.xxx.com/path-to?go-get=1
Enter passphrase for key '~/.ssh/id_rsa':

And after I input my password it hangs for hours without showing anything.

I also tried-

$ sudo go get git.xxx.com/path-to/package@v0.0.3

go get git.xxx.com/path-to/package@v0.0.3: git.xxx.com/path-to/package@v0.0.3: invalid version: unknown revision v0.0.3

But the repository indeed has a tag v0.0.3. And If I try without version-

$ sudo go get git.xxx.com/path-to/package

go get git.xxx.com/path-to/package: module git.xxx.com/path-to/package: git ls-remote -q origin in ~/go/pkg/mod/cache/vcs/bcb4baa8ab83c8bb452456922f12d22e1981b76bd2649d163d0c53c6: exit status 128:
    gitlab@git.xxx.com: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.

But I can clone this repository. So I have access rights and have this in ~/.gitconfig file

[url "ssh://gitlab@git.xxx.com:2222/"]
    insteadOf = https://git.xxx.com/

Note that, everything was okay in my system (I could use go get) until I ran this command go clean -cache -modcache -i -r following this blog.

John Reese
  • 31
  • 4

3 Answers3

0

I am wondering why the port in the git config?, maybe is not the root cause but you can try

[url "git@gitlab.com:"]
    insteadOf = https://gitlab.com/
cperez08
  • 709
  • 4
  • 9
0

Let's assume that you already set .git config sshd_config correctly. You can try

cd $HOME # out of gopath
env GO111MODULE=off go get git.xxx.com/path-to/package
c1ayy
  • 1
  • 1
0

you can try use GOPRIVATe evn variable https://golang.org/cmd/go/#hdr-Module_configuration_for_non_public_modules

SpX
  • 169
  • 2
  • 6