Notification texts go here Contact Us Buy Now!

Go modules, private repos and gopath

I use a workaround with GITHUB_TOKEN to solve this.
  1. Generate GITHUB_TOKEN here
  2. export GITHUB_TOKEN=xxx
  3. git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/mycompany".insteadOf "https://github.com/mycompany"
I wrote up a solution for this on Medium: Go Modules with Private Git Repositories.
The way we handle it is basically the same as the answer above from Alex Pliutau, and the blog goes into some more detail with examples for how to set up your git config with tokens from GitHub/GitLab/BitBucket.
The relevant bit for GitLab:
git config --global \
  url."https://oauth2:${personal_access_token}@privategitlab.com".insteadOf \
  "https://privategitlab.com"

#or 

git config --global \
  url."https://${user}:${personal_access_token}@privategitlab.com".insteadOf \
  "https://privategitlab.com"
I hope it's helpful.
I use ls-remote git command to help resolve private repo tags and go get after it.
$ go env GO111MODULE=on
$ go env GOPRIVATE=yourprivaterepo.com
$ git ls-remote -q https://yourprivaterepo.com/yourproject.git
$ go get
I try to fix this issue and then solved with this... you need to set up 3 ENV on your local machine
GONOPROXY=privategitlab.company.com
GONOSUMDB=privategitlab.company.com
GOPRIVATE=privategitlab.company.com
this will solved your issue
At first you should set GOPRIVATE
go env -w GOPRIVATE=privategitlab.com
then you have two methods:
first method:
git config --global url."https://{userName}:{access_token}@privategitlab.com".insteadOf "http://privategitlab.com"
second method:
update or create ~/.netrc file and put below line and save it
machine privategitlab.com login {username} password {access_token}
I prefer the second method because if you have group and subgroup in git, first method don't work

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.