Error when “go get” or “go mod tidy” got “invalid version” and “could not read Username” of a private repository?

Muhammad Tri Wibowo
1 min readAug 27, 2024

--

when go get

go get github.com/private_company/private_repo@v0.1.5-rc.2

or in go.mod i required

go 1.22.0

require (
....
https://github.com/private_company/private_repo@v0.1.5-rc.2
....
)

when i did

go mod tidy

i got this :

github.com/private_company/private_repo@v0.1.5-rc.2: verifying module: github.com/private_company/private_repov0.1.5-rc.2: reading https://sum.golang.org/lookup/github.com/private_company/private_repo@v0.1.5-rc.2: 404 Not Found
server response:
not found: github.com/private_company/private_repo@v0.1.5-rc.2: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/3180b115d5c32203ea1f078a3b55b3a5bacc1245f7f6b248af6df205202253d9: 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.

the solution is :

go env -w "GOPRIVATE=github.com/private_company/*, github.com/another_company/*"

or if you still got error, you need set GONOPROXY too

go env -w "GONOPROXY=github.com/private_company/*, github.com/another_company/*"

make sure to add quotes to keep my shell (zsh) from trying to expand the glob pattern (*): go env -w "GOPRIVATE=github.com/private_company/*"

reference :

git — How to fix “invalid version” and “could not read Username” in “go get” of a private repository? — Stack Overflow

--

--

No responses yet