go get results in 'terminal prompts disabled' error for github private repo

I found this extremely helpful, and it solved my problem. This command will allow your 2FA to do its thing (and save you the trouble of entering your username and password):

For Github:

git config --global --add url."[email protected]:".insteadOf "https://github.com/"

For Gitlab:

git config --global --add url."[email protected]:".insteadOf "https://gitlab.com/"

Source: http://albertech.blogspot.com/2016/11/fix-git-error-could-not-read-username.html

If you're not using 2FA, you can still use SSH and this will work.

Resulting .gitconfig will be like:

[url "[email protected]:"]
    insteadOf = https://github.com/

go get disables the "terminal prompt" by default. This can be changed by setting an environment variable of git:

env GIT_TERMINAL_PROMPT=1 go get github.com/examplesite/myprivaterepo

Tags:

Git

Go