Enabling go get through SSH
Got something like:
$ go get github.com/foo/bar@latest
go: downloading github.com/foo/bar v0.21.0
go: downloading github.com/foo/bar v0.0.0-20221202205032-05c20c95981f
go: github.com/foo/bar@latest: github.com/foo/bar@v0.21.0: verifying module: github.com/foo/bar@v0.21.0: reading https://sum.golang.org/lookup/github.com/foo/bar@v0.21.0: 404 Not Found
server response:
not found: github.com/foo/bar@v0.21.0: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/d12d86d0213924d97b3bc5ea4485dd14dd04c1abb64195c9c905f1cc0b63e1c0: exit status 128:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
This is because you’ve set up SSH to work with git but go get
uses HTTPS. the
recommended link is a good starting
point, but luck has it that you’ll probably have to set GOPRIVATE
. That one I
keep forgetting about, so this is your friendly reminder :)
TLDR;
First:
git config — global url."ssh://git@github.com/".insteadOf "https://github.com/"
Then:
go env -w GOPRIVATE=github.com/<company>