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

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

github - go build with private repositories

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:[email protected]"]
    insteadOf = https://github.com
[url "ssh://[email protected]/"]
    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/[email protected]/go.mod: 
  verifying module: github.com/x/[email protected]/go.mod: 
  reading https://sum.golang.org/lookup/github.com/xx/[email protected]: 410 Gone
server response:
  not found: github.com/x/[email protected]: 
  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.

question from:https://stackoverflow.com/questions/65602509/go-build-with-private-repositories

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

1 Answer

0 votes
by (71.8m points)

Your git config should look something like [url "[email protected]:"] 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...