Gabriel
Gabriel

Reputation: 5723

Invalid version and https references when importing private repo in golang

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?

Upvotes: 5

Views: 8877

Answers (3)

Ajit Surendran
Ajit Surendran

Reputation: 777

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

Upvotes: 0

matt jaehn
matt jaehn

Reputation: 51

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.

Upvotes: 5

VonC
VonC

Reputation: 1323753

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.

Upvotes: 4

Related Questions