1

I'm on a Apple MAC Laptop, go get command is not working. I have normal git access, I can git clone and git commit and git push. Why does this go get command not work?

temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
    ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
temp % go get github.com/MYCOMPANY/myproject
go get: module github.com/MYCOMPANY/myproject: git ls-remote -q origin in /Users/someuser/go/pkg/mod/cache/vcs/1872293eea4df8de643499713e2d8621a72624bb2514a7a88c1182d1869ef891: exit status 128:
    ssh: Could not resolve hostname github.com:MYCOMPANY: nodename nor servname provided, or not known
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
Phil
  • 46,436
  • 33
  • 110
  • 175
  • 2
    Does this answer your question? [What's the proper way to "go get" a private repository?](https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository) – Maneesh Babu M Jan 03 '22 at 04:58
  • 1
    Check the GOPRIVATE variable (`GOPRIVATE=github.com/MYCOMPANY/*`) and the git/config for: ```bash [url "git@github.com:"] insteadOf = https://github.com/ ``` The changes are required when working with private repos. – elulcao Jan 03 '22 at 14:18

2 Answers2

4

This is what works for me, based on @elulcao

go env -w GOPRIVATE=github.com/COMPANYNAME
git config --global --add url."git@github.com:".insteadOf "https://github.com/"

Then I can do

go mod download

In the projects git folder or go get

Phil
  • 46,436
  • 33
  • 110
  • 175
-1

'go get' by default does not support private repositories. It only supports public repos.

If you want to get private repos please refer to this link