Home > Article > Backend Development > git ls-remote succeeds but go get fails
php editor Apple encountered a problem when using Git and Go language to develop projects: the git ls-remote command can successfully obtain the information of the remote warehouse, but using the go get command fails Unable to successfully download dependent packages. This problem has troubled the editor for a long time. After constant attempts and debugging, I finally found a solution. In this article, we will introduce the cause and solution of this problem in detail, hoping to be helpful to developers who encounter the same problem.
The git ls-remote command is successful for the repository as shown below.
git ls-remote https://internal.net/dir1/dir2/dir3/repo warning: redirecting to https://internal.net/dir1/dir2/dir3/repo.git/ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx head yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy refs/heads/master
However, when using go get, cmd fails and cannot find the repository. The error output is trying to find .git in 1 directory above the repository structure.
go get internal.net/dir1/dir2/dir3/repo@master go: internal.net/dir1/dir2/dir3/repo@master: invalid version: git ls-remote -q origin in /Users/{{UserId}}/go/pkg/mod/cache/vcs/xyz...: exit status 128: remote: The project you were looking for could not be found or you don't have permission to view it. fatal: repository 'https://internal.net/dir1/dir2.git/' not found
My privatization is
goprivate=internal.net
What am I missing here in order for go get to succeed?
Add the vcs suffix in the private module path to mark the repository root prefix:
go get internal.net/dir1/dir2/dir3/repo.git@master
See Direct access to private modules:
An internal http server may still be required to resolve module paths into repository urls . For example, when the go command downloads module corp.example.com/mod
, it sends a get to https://corp.example.com/mod?go-get=1
request and will look for the url in the repository response. To avoid this requirement, make sure each private module path has a vcs suffix (such as .git
) marking the repository root prefix. For example, when the go command downloads module corp.example.com/repo.git/mod
, it will clone it at https://corp.example.com/repo.git
or ssh://corp.example's git repository.com/repo.git
without making additional requests.
Please note that the vcs suffix is part of the module path, so it should be included wherever the module path is used. include:
module
Command
module internal.net/dir1/dir2/dir3/repo.git
require
Command
require internal.net/dir1/dir2/dir3/repo.git v0.0.1
Import declaration
import "internal.net/dir1/dir2/dir3/repo.git/pkg/util"
there are more.
The above is the detailed content of git ls-remote succeeds but go get fails. For more information, please follow other related articles on the PHP Chinese website!