Skip to content

Instantly share code, notes, and snippets.

@katylava
Last active August 24, 2017 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katylava/47affb3a9248cbfbf179bec6a1079cd7 to your computer and use it in GitHub Desktop.
Save katylava/47affb3a9248cbfbf179bec6a1079cd7 to your computer and use it in GitHub Desktop.
go get private repo

Problem

> go get github.com/myorg/private-repo

# cd .; git clone https://github.com/myorg/private-repo mygopath/src/github.com/myorg/private-repo
Cloning into 'mygopath/src/github.com/myorg/private-repo'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/myorg/private-repo: exit status 128

Prerequisites

  • You are on a Mac
  • You have installed git via homebrew or xcode command line tools

Solution

1: Configure osxkeychain credential helper

git config --global credential.helper osxkeychain

more info

2: Create a personal access token

If you don't have two-factor auth on your Github account, then skip to #3

Go to Github.com > Settings > Developer Settings > Personal Access Tokens and click "Generate new token". Select all the permissions, or don't, it's up to you... but it will definitely work if you select all of them. Copy the token and use it for your password in the next step – Github won't show you the token again.

3: Initialize keychain

Pick any private repo you have access to and copy its https clone URL. cd to somewhere where you can clone it and run git clone with that URL. You will be prompted for your username and password – use your personal access token as your password if you have two-factor auth. The osxkeychain credential helper will save them to your keychain.

4: Try again

Run your go get ... command again and it should work because the osxkeychain helper will read your username and password from your keychain. It might seem to hang for a bit while it reads it (or maybe it hung for me for some other reason idk).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment