3

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

git config --global url.git@github.com:.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/util@v0.0.0-20200411022955-454673685ff5: verifying module: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: reading https://sum.golang.org/lookup/github.com/!X!X!X/util@v0.0.0-20200411022955-454673685ff5: 410 Gone
        server response:
        not found: github.com/XXX/util@v0.0.0-20200411022955-454673685ff5: 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?

Gabriel
  • 5,453
  • 14
  • 63
  • 92

2 Answers2

4

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://git@github.com/"]
        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.

matt jaehn
  • 41
  • 3
3

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

git config --global url."git@github.com:".insteadOf "https://github.com/"

See this gist as an example.

It includes:

An alternative to using git@github.com 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}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250