git push error “remote: Invalid username or password. fatal: Authentication failed”

I have 2-factor authentication enabled on my account. The repo is my own and I was unable to push changes to a private branch.

Steps to resolve

1. Check your remote of repo

$ git remote -v
origin (fetch)
origin (push)

Looked carefully, I was trying to push using https.

2. I updated local system’s SSH keys to my github account.

3. Next, I changed the remote to SSH.

# Remove original origin
$ git remote remove origin 

# Added SSH origin
$ git remote add origin

#Pushed changes
$ git push origin fix_shortcuts
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 536 bytes | 536.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: Create a pull request for 'fix_shortcuts' on GitHub by visiting:
* [new branch] fix_shortcuts -> fix_shortcuts

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: