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):
git config –global –add url.”[email protected]:”.insteadOf “https://github.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.
Edit: added the –add flag as suggested by slatunje.
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