I’m experiencing an issue when trying to access a private GitHub repository using the go get command. Here’s a bit of background:
I created a private repo named mycompany/private-repo on GitHub via their web interface. On my primary workstation, everything went smoothly:
$ cd $GOPATH
$ go get github.com/mycompany/private-repo
I added a new file called handler.go, committed the changes, and pushed them to the repo successfully:
$ vim handler.go
$ git add handler.go
$ git commit -m "Add handler function"
$ git push origin main
But when I attempted to clone it on a different laptop, I encountered the following error:
$ cd $GOPATH
$ go get github.com/mycompany/private-repo
cd .; git clone https://github.com/mycompany/private-repo /home/user/go/src/github.com/mycompany/private-repo
Cloning into '/home/user/go/src/github.com/mycompany/private-repo'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/mycompany/private-repo: exit status 128
I anticipated a prompt for my GitHub credentials, but it didn’t happen and failed instead. How can I properly authenticate for private repositories using go get?