Use Go module from private repository


go get<user>/<repo>

Quick start for GitHub Private Repo

  1. Add private repo url(s) GOPRIVATE environment.
    go env -w<user>/*
  2. Run go get with enable terminal prompt option
    GIT_TERMINAL_PROMPT=1 go get<user>/<repo>
  3. If prompt, input:
    Username Your GitHub Username
    Password Your GitHub Access Token


Setting GOPRIVATE to make go get bypass default GOPROXY and checkout from your private repo.
go env -w<user>/<repo>

  • If you want to append to existing GOPRIVATE, run:
    go env -w GOPRIVATE=$(go env GOPRIVATE),<user>/repo_a
  • You can also add multiple private repos or using wildcard (_).
    go env -w<user>/repo_a,<user>/repo_b
    go env -w<user>/_
  • If you don’t want to modify the go global environment file, you can run a one-time command<user>/<repo> go get<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<user>/<repo>

Username Your GitHub Username
Password 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.

macOS: Open Keychain and search, delete the item with Internet Password type.

Option 2: Modify Git Config

Github (also for GitLab / BitBucket)

  1. Generate GitHub Access Token
  2. Setup global config
    git config --global url."https://<token>".insteadOf ""

git config --global --remove-section url."https://<token>"

⚠️ Make sure to add a stroke / at the end of the target url.
url."https://<token>".insteadOf ""
url."https://<token>".insteadOf ""

Without the stroke, it may cause security issue. Hacker may setup a fake repo using (which match to steal your user token.


  1. Connecting to GitHub with SSH
  2. Setup global config
    git config --global [email protected]:.insteadOf

git config --global --remove-section [email protected]:

Check / edit git config manually

In case you want to check out current config state or you want to edit it, you can run:
git config --global -e

Option 3: Using .netrc

  1. Generate GitHub Access Token
  2. Create / edit ~/.netrc file and add:
    machine login <token>



🎉  Thanks for reading and hope you enjoy it. Feel free to check out my other posts and find me on X and GitHub!