Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "invalid version" and "could not read Username" in "go get" of a private repository?

Tags:

git

go

I want to use private repositories that are hosted at GitHub in another GoLang-project.

What I did:

  1. I created a private access token at my GitHub account settings
  2. did then:

    git config --global url."https://xxxxxx:[email protected]".insteadOf "https://github.com"

with "xxxxxx" as my real GitHub username and then the proper ACCESS_TOKEN.

  1. go get github.com/private/repo

However, I get always the following error:

go: downloading github.com/xxxxxxxx/yyyyyyyyy-go-sdk v0.0.0-20200307154628-cbcb73911013
go get github.com/xxxxxxxx/yyyyyyyyy-go-sdk: github.com/xxxxxxxx/[email protected]: verifying module: github.com/xxxxxxxx/[email protected]: reading https://sum.golang.org/lookup/github.com/xxxxxxxx/[email protected]: 410 Gone
    server response:
    not found: github.com/xxxxxxxx/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/5eca4f397ed3a418f58ee864965ed24936e21268780304d6941f5b3983d31ad1: exit status 128:
        fatal: could not read Username for 'https://github.com': terminal prompts disabled

I have also tried the following:

GONOSUMDB=github.com/myusername go get github.com/xxxxxx/yyy...

And according to some answers at StackOverflow for similar issues I tried to add ".git" after the repo-url. But this won't work at all.

What could this be and how can I fix this?

Versions:

♠ git --version
git version 2.25.0
hub version 2.14.2

♠ go version 1.14

like image 966
delete Avatar asked Mar 07 '20 16:03

delete


2 Answers

You did almost everything right, and only forgot one important step.

You need to tell Go to not check checksums, as you are operating on your own private repositories:

go env -w GOPRIVATE=github.com/mycompany/*

Replace mycompany with your username on github or the name of your company and go get will most likely work as expected.

like image 196
itinance Avatar answered Oct 12 '22 00:10

itinance


I have a solution that might help. this problem occurs in Golang version above 1.13. This happens when we use a private module in our project. Due to the Go Get command run, the golang will do a proxy checksum. So the alternative is you need to add GOPRIVATE environment in your environment.

export GOPRIVATE="github.com/private/repo"

Or if it doesn't work, try adding with GONOPROXY environment.

export GONOPROXY="github.com/private/repo"
like image 26
Teuku Mulia Ichsan Avatar answered Oct 12 '22 01:10

Teuku Mulia Ichsan