Invalid version and https references when importing private repo in golang
Asked Answered
A

3

5

Trying to import a private repo as package in golang. Did:

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

So in theory all references to https are replaced by the ssh version.

github.com/XXX/util

Is my private repo which is a go module.

I do a go get -v and get:

[gabriel@xiridio backend]$ go get -v
go: finding module for package github.com/XXX/util
go: downloading github.com/XXX/util v0.0.0-20200411022955-454673685ff5
go: finding module for package github.com/XXX/util
main.go:12:2: github.com/XXX/[email protected]: verifying module: github.com/XXX/[email protected]: reading https://sum.golang.org/lookup/github.com/!X!X!X/[email protected]: 410 Gone
        server response:
        not found: github.com/XXX/[email protected]: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/f1fdc5cc42a6995f954688df06783c05d28e4a60e9aaf6930a88a2487b913907: exit status 128:
                fatal: could not read Username for 'https://github.com': terminal prompts disabled

Looks like there is a "version" issue and also for some reason there is still references to https. What else can I do?

Annmarieannnora answered 11/4, 2020 at 4:36 Comment(0)
L
4

Just to be sure, I prefer using quotes for the git config command:

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

See this gist as an example.

It includes:

An alternative to using [email protected] is to generate a personal access token on your GitHub account, grant it repo access, and then use the following instead:

git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"

Check also "go get results in 'terminal prompts disabled' error for GitHub private repo", which mentions the use of GOPRIVATE.

Lymphangitis answered 11/4, 2020 at 5:33 Comment(3)
Thank you. Using the git config AND the GOPRIVATE worked.Annmarieannnora
@GabrielA.Zorrilla which of the two git config did you used?Lymphangitis
The quotes did not have any influence on the output to ~/.gitconfig, so both are valid.Annmarieannnora
I
5

There were 2 things I had to do to be able to pull my private modules using go 1.18:

  1. equivalent to @VonC 's answer, added the following 2 lines to my ~/.gitconfig:
[url "ssh://[email protected]/"]
        insteadOf = https://github.com/
  1. explicitly added each of my private module git paths to the GOPRIVATE variable:
go env -w GOPRIVATE="github.com/projname/mod1,github.com/projname/mod2,github.com/projname/mod3"

i believe this is both necessary and sufficient, or at least sufficient.

note that you will need to have local access to your private repos with ssh for this to work.

Idocrase answered 22/8, 2022 at 2:22 Comment(0)
L
4

Just to be sure, I prefer using quotes for the git config command:

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

See this gist as an example.

It includes:

An alternative to using [email protected] is to generate a personal access token on your GitHub account, grant it repo access, and then use the following instead:

git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"

Check also "go get results in 'terminal prompts disabled' error for GitHub private repo", which mentions the use of GOPRIVATE.

Lymphangitis answered 11/4, 2020 at 5:33 Comment(3)
Thank you. Using the git config AND the GOPRIVATE worked.Annmarieannnora
@GabrielA.Zorrilla which of the two git config did you used?Lymphangitis
The quotes did not have any influence on the output to ~/.gitconfig, so both are valid.Annmarieannnora
G
0

Make sure you don't have 2 entries in the .gitconfig file. The first one takes precedence.

Gregson answered 15/8 at 22:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.