go modules – Golang go get failed with git ls-remote -q using the wrong url @ Go 1.13-ThrowExceptions

Exception or error:

Ok according to https://github.com/golang/go/issues/34094, go 1.13.3 fixed this problem

Env: Go 1.13, Windows

I got a fresh copy of Go on a Windows machine and try to build my project here.

However, the mod which used to work is failing right now:

C:\xxx> go get -v private.repo.com/dir/utils.git
get "private.repo.com/dirxxxx": found meta tag get.metaImport{Prefix:"private.repo.com/dirxxxx", VCS:"git", RepoRoot:"https://private.repo.com/dirxxxx.git"} at //private.repo.com/dirxxxx?go-get=1
get "private.repo.com": found meta tag get.metaImport{Prefix:"private.repo.com", VCS:"git", RepoRoot:"https://private.repo.com.git"} at //private.repo.com/?go-get=1
go: finding private.repo.com/dirxxxx/utils.git v0.0.5
go: downloading private.repo.com/dirxxxx/utils.git v0.0.5
go: extracting private.repo.com/dirxxxx/utils.git v0.0.5
go get private.repo.com/dirxxxx/utils.git: git ls-remote -q https://private.repo.com/dirxxxx.git in C:\Users\admin\go\pkg\mod\cache\vcs\227f0870299637a3fadb469f608679095de39005c860e3949d82a547e8c30143: exit status 128:
        GitLab: The project you were looking for could not be found.
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.

Which is, well, not wrong since there is indeed no https://private.repo.com/dirxxxx.git.

What we have is a https://private.repo.com/dirxxxx/utils.git. How can I force go git to use a certain tag or skip the ls-remote since it already found a version and extracting the files lol

I config GOPROXY=direct according to https://golang.org/doc/go1.13, since I am using a private repo.

And also set proxy & stuff following the guide but problems remain.

Any tips? Thanks in advance!

How to solve:


If you have moved your repository from https://private.repo.com/dirxxxx.git to https://private.repo.com/dirxxxx/utils.git, you can use the replace directive in your go.mod file to define alias paths:

replace private.repo.com/dirxxxx => private.repo.com/dirxxxx/utils v0.0.5

This way, when you run go get private.repo.com/dirxxxx, it will fetch from https://private.repo.com/dirxxxx/utils.git instead.

HTTPS Authentication

And if your repository is password protected, you can config your git with the username and password like this:

git config --global url."https://username:password@private.repo.com/".insteadOf "https://private.repo.com/"

Which generates a section in your ~/.gitconfig like this:

[url "https://username:password@private.repo.com/"]
    insteadOf = https://private.repo.com/

Leave a Reply

Your email address will not be published. Required fields are marked *