(I am using go 1.15 at linux. The latest stable version while posting this answer)
I solved the problem and posting here, hopefully, this will help other people one day. I don't find any correct answer by my search online.
In short, the answer is to use .git
suffix in all places. Without .git
suffix, go mod tidy
and go get
will use https
instead of ssh
(git).
At Client:
The file ~/.gitconfig
(at linux) if you use /repopath/foo.git
path at server:
[url "ssh://[email protected]"]
insteadOf = https://private.com
The file ~/.gitconfig
(at linux) if you use ~/repopath/foo.git
path at server:
[url "[email protected]:"]
insteadOf = https://private.com/
Execute the following to update ~/.config/go/env
at linux:
go env -w GOPRIVATE=private.com
In go.mod
, it should use
require private.com/repopath/foo.git v0.1.0
In file.go
, it should be
import private.com/repopath/foo.git
At SSH Server
in foo.git/go.mod
at private server should have:
module private.com/repopath/foo.git
And make sure the git repo at server has tag version v0.1.0
. Don't forget to use git push --tags
at client to update the tag version to the server. Without --tags
, tag version will not be pushed.
After adding .git
suffix to all the required places, go mod tidy
and go get
will no longer send https request.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…