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."git@github.com:".insteadOf "https://github.com/"
For Gitlab:
git config --global --add url."git@gitlab.com:".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 "git@github.com:"]
insteadOf = https://github.com/