GOPRIVATE=github.com/<user>/*
GIT_TERMINAL_PROMPT=1
go get github.com/<user>/<repo>
GOPRIVATE environment.go env -w GOPRIVATE=github.com/<user>/*go get with enable terminal prompt optionGIT_TERMINAL_PROMPT=1 go get github.com/<user>/<repo>Username Your GitHub UsernamePassword Your GitHub Access TokenSetting GOPRIVATE to make go get bypass default GOPROXY and checkout from your private repo.go env -w GOPRIVATE=github.com/<user>/<repo>
GOPRIVATE, run:go env -w GOPRIVATE=$(go env GOPRIVATE),github.com/<user>/repo_ago env -w GOPRIVATE=github.com/<user>/repo_a,github.com/<user>/repo_bgo env -w GOPRIVATE=github.com/<user>/_GOPRIVATE=github.com/<user>/<repo> go get github.com/<user>/<repo>After setting GOPRIVATE, you should choose an authentication method to for git that called by go get.
I am personally recommend this option because it will save your credential in system keychain instead of file.
If you get terminal prompts disabled error after you running go get that means you have not save your credential. To enable terminal prompts, just run:GIT_TERMINAL_PROMPT=1 go get github.com/<user>/<repo>
Username Your GitHub UsernamePassword Your GitHub Access Token
Once you input current username and password, you can directly run go get to download go module from private repo without prompt forever.
Remove
macOS: OpenKeychain Access.appand searchgithub.com, delete the item with Internet Password type.
git config --global url."https://<token>@github.com/".insteadOf "https://github.com/"Remove
git config --global --remove-section url."https://<token>@github.com/"
⚠️ Make sure to add a stroke
/at the end of the target url.url."https://<token>@github.com/".insteadOf "https://github.com/"✅url."https://<token>@github.com".insteadOf "https://github.com"❌Without the stroke, it may cause security issue. Hacker may setup a fake repo using
https://github.com.hacker-site.com(which matchhttps://github.com) to steal your user token.
git config --global [email protected]:.insteadOf https://github.com/Remove
git config --global --remove-section [email protected]:
In case you want to check out current config state or you want to edit it, you can run:git config --global -e
~/.netrc file and add:machine github.com login <token>