remote: Invalid username or password.

$ git push
Username for 'https://github.com': Username
Password for 'https://Username@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/username/repository.git/'

What causes this error

This error message is self explanatory. It means that we are trying to use the invalid username or password. But I’m sure I’m using the correct username and password. In my case, this happened with me after I turned on a two-factor authentication (2FA) in my GitHub account. So I know what caused this error message.html

How to solve it

To solve this problem all we need to do is create a GitHub personal access token and use it instead of our GitHub password and a two-factor authentication code.git

Creating a GitHub personal access token.github

 

In the upper-right corner of any page, click your profile photo, then click Settings.web

In the left sidebar, click Developer settings.app

In the left sidebar, click Personal access tokens.ssh

Click Generate new token.ide

Give your token a descriptive name.this

Select the scopes, or permissions, you’d like to grant this token. To use your token to access repositories from the command line, select repo.url

Click Generate token.spa

Copy the token to your clipboard. For security reasons, after you navigate off the page, you will not be able to see the token again.

 

Note! Treat your tokens like passwords and keep them secret (if you don’t want other people to use the API on your behalf). When working with the API, use tokens as environment variables instead of hardcoding them into your programs.

Using a token on the command line.

 

Once we have a token, we can enter it instead of our password when performing Git operations over HTTPS. Just inter your token after prompted a password and then watch the magic happen…

git push
Username: your_username
Password: your_token

Note! Personal access tokens can only be used for HTTPS Git operations. If your repository uses an SSH remote URL, you will need to switch the remote from SSH to HTTPS.

Note! If you are not prompted for your username and password, your credentials may be cached on your computer. You can update your credentials in the Keychain to replace your old password with the token.


If this article helped you solve the problem then please leave a comment:smiley:

Thanks for reading!

相關文章
相關標籤/搜索