Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to build a go application that makes use of git repositories that are private. I have an ssh key for my github account and have the following in my .gitconfig file:

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

when I execute go test or go build I am asked for the passphrase. I then get a response:

go: found github.com/x/businesses in github.com/x/businesses v0.0.0-yy
go: cmd/main/cmd imports
  github.com/x/businesses: github.com/x/businesses@v0.0.0-yy/go.mod: 
  verifying module: github.com/x/businesses@v0.0.0-yy/go.mod: 
  reading https://sum.golang.org/lookup/github.com/xx/businesses@v0.0.0-yy: 410 Gone
server response:
  not found: github.com/x/businesses@v0.0.0-yy: 
  invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* 
  in tmp/gopath/pkg/mod/cache/vcs/zz: 
    exit status 128:
    fatal: could not read Username for 'https://github.com': terminal prompts disabled

I tried removing the top insteadOf in the .gitconfig for no reason other then to try something.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
401 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your git config should look something like [url "git@github.com:"] insteadOf = https://github.com/ or similar to what you have.

Then you can go get your pacakge by telling Go that your using a private repo like this: GOPRIVATE="github.com/your_username_or_org" go get github.com/name_or_org/repo_name

Also, I usually dont put a passprahse on my SSH keys since is kinda annoying to type it in each time but of course is more secure by adding it like someone pointed out in the comments.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...