4

Looking for a bit of help. I have a private repo hosted on a remote gitlab instance that I SHOULD be able to access. But no matter what I try, go get seems to be trying to use https instead of SSH. I can git clone, git fetch, etc without any issue. But as soon as I use go get, it fails.

First thing I did was add this: git config --global --add url."git@git.mydomain.io:".insteadOf "https://git.mydomain.io/"

Then I cd to my project directory and run a go get and it fails trying to authenticate over HTTPS with a "fatal: could not read Username for 'https://git.my.domain': terminal prompts disabled":

PS C:\Users\User\go\src\git.my.domain\ps\wk\collector> go get            
go: downloading git.my.domain/ps/mqtt v0.0.0-20220903204713-6f195510d46e
go: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: verifying module: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: reading https://sum.golang.orglookup/git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: 404 Not Found
        server response:
        not found: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/v
cs/3a728c5d3b6137ea441372540f3e7bc1390c001346a70d5b7df3eda6d5e7316d: exit status 128:
                fatal: could not read Username for 'https://git.my.domain': terminal prompts disabled
        Confirm the import path was entered correctly.
        If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
go: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: verifying module: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: reading https://sum.golang.org/lookup/git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: 404 Not Found
        server response:
        not found: git.my.domain/ps/mqtt@v0.0.0-20220903204713-6f195510d46e: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/v
cs/3a728c5d3b6137ea441372540f3e7bc1390c001346a70d5b7df3eda6d5e7316d: exit status 128:
                fatal: could not read Username for 'https://git.my.domain': terminal prompts disabled
        Confirm the import path was entered correctly.
        If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
go: module git.my.domain/ps/wk/collector/service: git ls-remote -q origin in C:\Users\User\go\pkg\mod\cache\vcs\7d02e96755cff57eaec3323ab70c24a12ab19
eac805790ed1220d62b15affcf8: exit status 128:
        remote:
        remote: ========================================================================
        remote:
        remote: The project you were looking for could not be found.
        remote:
        remote: ========================================================================
        remote:
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.
go: module git.my.domain/ps/wk/collector/service/service: git ls-remote -q origin in C:\Users\User\go\pkg\mod\cache\vcs\7d02e96755cff57eaec3323ab70c2
4a12ab19eac805790ed1220d62b15affcf8: exit status 128:
        remote:
        remote: ========================================================================
        remote:
        remote: The project you were looking for could not be found.
        remote:
        remote: ========================================================================
        remote:
        fatal: Could not read from remote repository.

        Please make sure you have the correct access rights
        and the repository exists.

I'm going absolutely nuts. I've tried every combination of getting go get to use SSH:

git config --global --add url."git@git.mydomain.io/".insteadOf "https://git.mydomain.io/"

git config --global --add url."git@git.mydomain.io".insteadOf "https://git.mydomain.io"

git config --global --add url."ssh://git@git.mydomain.io:".insteadOf "https://git.mydomain.io/"
...

Is there something special I have to do somewhere? I just don't understand why go get is using HTTPS while git commands appear to be correctly using SSH..

======================

EDIT: Ok more expirementing got me to realize that this IS working:

[url "ssh://git@git.mydomain.io"] insteadOf = https://git.mydomain.io/

because I get a new error:

        ssh: Could not resolve hostname git.mydomain.iops: Name or service not known
        fatal: Could not read from remote repository.

But as soon as I add that trailing slash to fix it, I get back to HTTPS errors. Is there something going on HTTPS wise that happens before ssh?

The Kaese
  • 419
  • 5
  • 15
  • Does it help? https://stackoverflow.com/questions/58203258/go-get-with-private-gitlab-repo – Christian Sep 20 '22 at 00:35
  • Sadly no.. I've tried with and without the ssh:// – The Kaese Sep 20 '22 at 01:33
  • 1
    The final URL you *want* is `ssh://git@git@mydomain.io/` instead of `https://git.mydomain.io/`, which means your first attempt was close, but lacked the `ssh://` in front. Your last attempt had the `ssh://` in front but then had a colon instead of a slash. – torek Sep 20 '22 at 01:40
  • No I mean, I've tried all those options. ssh://, no ssh://, no :, with /, without /, etc. – The Kaese Sep 20 '22 at 01:46
  • Have you tried removing the final slash from the https url : `https://git.mydomain.io` ? – LeGEC Sep 20 '22 at 05:12

1 Answers1

0

Try modifying your ~/.gitconfig file directly, make sure the entry to your private repo looks like this

[url "git@gitlab.com:"] insteadOf = https://gitlab.com

Maybe something with the syntax.

Also add the url (without https://) into your $GONOPROXY.

lsd
  • 504
  • 1
  • 4
  • 16