简体   繁体   中英

'go get' doesn't work with my own git repository

I have set up git repo on my own server and can deal with it via ssh, something like that (I use ssh key for it)

git clone username@myserver.com:/home/git/repo.git

and I have set up git daemon, so I can use it something like following

git clone username@myserver.com:/home/git/repo

I have configured local git to use ssh instead of https, so my ~/.gitconfig has following

[url "username@myserver.com:"]
         insteadOf = https://myserver.com

and following works well

git clone https://myserver.com/home/git/repo

but when I try to deal with it by 'go get'

go get myserver.com/home/git/repo

I got an error

go get: unrecognized import path "myserver.com/home/git/repo": https fetch: Get "https://myserver.com/home/git/repo?go-get=1": dial tcp HERE_IS_IP_ADDR:443: connect: connection refused

I have already tried to do something like that

go env -w GOPRIVATE="myserver.com/home/git/repo"

but it doesn't work.

I use go version go1.16.4 linux/amd64

Could somebody help with it?

When you designate your repo as an import path to go, try adding .git to the chunk that represents the root of the target repository :

go get myserver.com/home/git/repo.git

# to get a subpackage:
go get myserver.com/home/git/repo.git/sub/pkg

go help get has the following paragraph :

For more about how 'go get' finds source code to download, see 'go help importpath'.

go help importpath explains, in the Remote import paths section :

a few hosting platforms, like github.com or bitbucket.org , are automatically handled ; for other hosting solutions :

To declare the code location, an import path of the form

repository.vcs/path

specifies the given repository, ...

where .vcs can be one of .git, .hg, .svn, .bzr, .fossil .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM