3

I have one Go project that use a private library hosted in github. Currently am using go modules, so I configured the access to github via SSH so I could use go get github.com/myorg/mylibrary this was working before, but now am getting the next message when I do again go get github.com/myorg/mylibrary@commitId:

github.com/myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: verifying module: 
github.com/myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: reading https://sum.golang.org/lookup/github.com/!myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: 410 Gone
        server response:
        not found: github.com/myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/b186106557bfd44bc932dd151f0fcd2758d8d89d09ab32f8915de7f151e393d1: exit status 128:
                fatal: could not read Username for 'https://github.com': terminal prompts disabled 

I already tried with:

env GIT_TERMINAL_PROMPT=1 go get github.com/myorg/mylibrary@commitId

but still got the same. So, why am getting this? and how could I overcome it?

Wendelin
  • 2,354
  • 1
  • 11
  • 28
Sredny M Casanova
  • 4,735
  • 21
  • 70
  • 115

1 Answers1

0

you can use ssh + public key to access github private project with go module

first replace git HTTP scheme to ssh scheme

git config -e
// if you want replace scheme with global config use --global
git config --global -e

and then add below lines

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

ensure that your public key has been added to github

cat ~/.ssh/id_rsa.pub
// if file not found use ssh-keygen to generate it 
ssh-keygen

add public key to github access below URL add it

https://github.com/settings/keys

now you can get github private project within go mod

big pigeon
  • 85
  • 5