I face a build error when I ran go build

Error

$ go build
go: errors parsing go.mod:
*PATH TO CODE*/go.mod:3: invalid module version "latest": git ls-remote -q https://github.com/*private-org*/*repo/* in /*GOPATH*/pkg/mod/cache/vcs/4b486188857ac4620efdb99803c5499cd13b93e2651ab659f1535b63935a6d8f: exit status 128:
	fatal: could not read Username for 'https://github.com': terminal prompts disabled
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

How to solve

  • 1) Add this code to ~/.gitconfig

    [url "ssh://git@github.com/"]
    	insteadOf = https://github.com/
    
  • 2) Run it

    $ git config --global url."ssh://git@github.com/*private-org*/".insteadOf "https://github.com/*private-org*/"
    

I like (2) method.

Ref

issue
url..insteadOf