GO Lang terminal prompts disabled

GO Lang terminal prompts disabled
Photo by Alexander Schimmeck / Unsplash

Solving a repeating problem when importing private repository in GO

go get -u github.com/repo/mygorepo
go: downloading github.com/repo/mygorepo v1.0.4
go: github.com/repo/mygorepo@v1.0.4: verifying module: github.com/repo/mygorepo@v1.0.4: reading https://sum.golang.org/lookup/github.com/repo/mygorepo@v1.0.4: 404 Not Found
        server response:
        not found: github.com/repo/mygorepo@v1.0.4: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/96fed60d6c9865c962fb397032ec293e8cff6c3e2800c4ffed189c47a8b5023c: 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.

Solution

Step 1:

go env -w GOPRIVATE=github.com/repo/mygorepo

Step 2:

env GIT_TERMINAL_PROMPT=1 go get -u github.com/repo/mygorepo