自分のプライベートリポジトリをgo getすると以下のようなエラーが発生する。
$ go get github.com/jnst/my-private-repo # cd .; git clone https://github.com/jnst/my-private-repo /Users/jnst/go/src/github.com/jnst/my-private-repo Cloning into '/Users/jnst/go/src/github.com/jnst/my-private-repo'... fatal: could not read Username for 'https://github.com': terminal prompts disabled package github.com/jnst/my-private-repo: exit status 128
原因
普段は GitHub の SSH Keys に公開鍵を登録して SSH 認証しているので git@github.com:jnst/my-private-repo.git のような URL を使ってプッシュしたりしてると思うけど、go get の場合は HTTP 経由で行わないとダメらしい。
Personal access tokens を生成して HTTP の URL にくっつけてあげれば OAuth 認証(?)可能になるため、go get も使うことができる。
やり方
https://github.com/settings/tokens
ここから repo 権限にチェックつけて(Organization のリポジトリなら admin:org も必要のはず)トークンを生成してコピーして下記コマンドを実行。
$ git config --global url."https://c61axxxxxxxxxxxxxxx:x-oauth-basic@github.com/".insteadOf "https://github.com/"
c61axxxxxxxxxxxxxxx の部分に生成したトークンを貼っ付ける。
そうすると実行した内容が ~/.gitconfig に追記されて、この状態なら go get github.com/jnst/my-private-repo が可能になっている。
$ go get github.com/jnst/my-private-repo # cd /Users/jnst/go/src/github.com/jnst/my-private-repo; git show-ref package github.com/jnst/my-private-repo: exit status 1