Pushing a local repo to a GitHub repo which has dual-factor authentication
I'm trying to push code in my local repo (on an OS X 10.8.5 system with the GitHub app installed and logged into) to a repo I created on GitHub via their website, using the command line. Oddly, when I try to git push -u origin master
, I log in with my (correct) GitHub credentials, and get fatal: Authentication failed
.
I do use dual-factor authentication, but I've authenticated the machine with this issue through the GitHub application. I've also got the appropriate SSH key for this operation.
What's the cause of this issue? How can it be fixed?
Solution 1:
Two-factor auth generally doesn't work per machine – it works per client. When you log in to GitHub using a web browser, it's the web browser that remembers cookies with both the auth info, and the 2FA status. git does not know about that.
To push over HTTP(S), you will need to generate a secondary password ("personal access token") in GitHub's application settings page (use the "Create new token" button). Note that git can remember the "password" if you don't want to retype/paste it every time.