GitHub: invalid username or password
GithubGithub Problem Overview
I have a project hosted on GitHub. I fail when trying to push my modifications on the master. I always get the following error message
Password for 'https://[email protected]':
remote: Invalid username or password.
fatal: Authentication failed for 'https://[email protected]/eurydyce/MDANSE.git/'
However, setting my ssh key to github seems ok. Indeed, when I do a ssh -T [email protected]
I get
Hi eurydyce! You've successfully authenticated, but GitHub does not provide shell access.
Which seems to indicate that everything is OK from that side (eurydyce being my github username). I strictly followed the instructions given on github and the recommendations of many stack discussion but no way. Would you have any idea of what I may have done wrong?
Github Solutions
Solution 1 - Github
After enabling Two Factor Authentication (2FA), you may see something like this when attempting to use git clone
, git fetch
, git pull
or git push
:
$ git push origin master
Username for 'https://github.com': your_user_name
Password for 'https://[email protected]':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/your_user_name/repo_name.git/'
Why this is happening
From the GitHub Help documentation:
>After 2FA is enabled you will need to enter a personal access token instead of a 2FA code and your GitHub password.
>
> ...
>
>For example, when you access a repository using Git on the command line using commands like git clone
, git fetch
, git pull
or git push
with HTTPS URLs, you must provide your GitHub username and your personal access token when prompted for a username and password. The command line prompt won't specify that you should enter your personal access token when it asks for your password.
How to fix it
- Generate a Personal Access Token. (Detailed guide on Creating a personal access token for the command line.)
- Copy the Personal Access Token.
- Re-attempt the command you were trying and use Personal Access Token in the place of your password.
Related question: https://stackoverflow.com/a/21374369/101662
Solution 2 - Github
https://[email protected]/eurydyce/MDANSE.git is not an ssh url, it is an https one (which would require your GitHub account name, instead of 'git
').
Try to use ssh://[email protected]:eurydyce/MDANSE.git
or just [email protected]:eurydyce/MDANSE.git
git remote set-url origin git@github.com:eurydyce/MDANSE.git
The OP Pellegrini Eric adds:
> That's what I did in my ~/.gitconfig
file that contains currently the following entries [remote "origin"] [email protected]:eurydyce/MDANSE.git
This should not be in your global config (the one in ~/
).
You could check git config -l
in your repo: that url should be declared in the local config: <yourrepo>/.git/config
.
So make sure you are in the repo path when doing the git remote set-url
command.
As noted in Oliver's answer, an HTTPS URL would not use username/password if two-factor authentication (2FA) is activated.
In that case, the password should be a PAT (personal access token) as seen in "Using a token on the command line".
That applies only for HTTPS URLS, SSH is not affected by this limitation.
Solution 3 - Github
Solution steps:
- Control Panel
- Credential Manager
- Click Windows Credentials
- In Generic Credential section ,there would be git url, update username and password
- Restart Git Bash and try for clone
Solution 4 - Github
> If like me you just updated your password and ran git push
to run into this issue, then there's a super easy fix.
For Mac users only. You need to delete your OSX Keychain access entries for GitHub. You can do it via terminal by running the following commands.
Deleting your credentials via the command line
Through the command line, you can use the credential helper directly to erase the keychain entry.
To do this, type the following command:
git credential-osxkeychain erase
host=github.com
protocol=https
# [Now Press Return]
If it's successful, nothing will print out. To test that it works, try and clone a repository from GitHub or run your previous action again like in my case git push
. If you are prompted for a password, the keychain entry was deleted.
Solution 5 - Github
When using the https://
URL to connect to your remote repository, then Git will not use SSH as authentication but will instead try a basic authentication over HTTPS. Usually, you would just use the URL without a username, e.g. https://github.com/username/repository.git
, and Git would then prompt you to enter both a username (your GitHub username) and your password.
If you use https://[email protected]/username/repository.git
, then you have preset the username Git will use for authentication: something
. Since you used https://[email protected]
, Git will try to log in using the git
username for which your password of course doesn’t work. So you will have to use your username instead.
The alternative is actually to use SSH for authentication. That way you will avoid having to type your password all the time; and since it already seems to work, that’s what you should be using.
To do that, you need to change your remote URL though, so Git knows that it needs to connect via SSH. The format is then this: [email protected]:username/repository
. To update your URL use this command:
git remote set-url origin git@github.com:username/repository
Solution 6 - Github
2FA is enabled and getting error remote: Invalid username or password. fatal: Authentication failed for
If you set 2FA is enabled in GitHub you will need to enter a personal access token instead of a 2FA code and your GitHub password.
How to fix it
- https://github.com/settings/tokens generated token
- Copy the Personal Access Token
- Now enter Personal Access Token in the place of your password during git operation
Solution 7 - Github
Instead of git pull
also try git pull origin master
I changed password, and the first command gave error:
$ git pull
remote: Invalid username or password.
fatal: Authentication failed for ...
After git pull origin master
, it asked for password and seemed to update itself
Solution 8 - Github
just try to push it to your branch again. This will ask your username and password again, so you can feed in the changed password. So that your new password will be stored again in the cache.
Solution 9 - Github
That problem happens sometimes due to wrong password. Please check if you are linked with AD password (Active Directory Password) and you recently changed you AD password but still trying git command with old password or not.
Update old AD password
Control Panel > Credential Manager > Windows Credential > change github password with my new AD password
Solution 10 - Github
I have got the success using the following commands.
git config --unset-all credential.helper
git config --global --unset-all credential.helper
git config --system --unset-all credential.helper
Try and let me know if these are working for you.
Solution 11 - Github
No need to rely on Generating a Personal Access Token and then trying and use Personal Access Token in the place of your password.
Quick fix is to set your remote URL to point to ssh
not https
.
Do this git remote set-url origin [email protected]:username/repository
Solution 12 - Github
I am getting this while cloning app from bitbucket:
Cloning into 'YourAppName'...
Password for 'https://youruser id':
remote: Invalid username or password
I solved it. Here you need to create password for your userid
Solution 13 - Github
I did:
$git pull origin master
Then it asked for the [Username] & [Password] and it seems to be working fine now.
Solution 14 - Github
Try this:
# git remote set-url origin git@github.com:username/repository
Solution 15 - Github
If you have just enabled 2FA :
Modify hidden config
file in ./git
hidden folder as follow :
[remote "origin"]
url = https://username:[email protected]/project/project.git
Solution 16 - Github
Disabling 2 factor authentication at github worked for me.
I see that there is a deleted answer that says this, with the deletion reason as "does not answer the question". If it works, then I think it answers the question...
Solution 17 - Github
Run Below command, and after than on every push and pull it will ask you to enter the username and password.
git config credential.helper ""
now when you pull/push you will be asked for git credentials. weather you are running through command prompt or Intellij Git.
Solution 18 - Github
You might be getting this error because you have updated your password. So on Terminal first make sure you clear your GitHub credentials from the keychain and then push your changes to your repo, terminal will ask for your username and password.
Solution 19 - Github
In case you get this error message in this situation:
- using github for entreprise
- using credential.helper=wincred in git config
- using your windows credentials which you changed recently
Then look at this answer: https://stackoverflow.com/a/39608906/521257
Windows stores credentials in a credentials manager, clear it or update it.
Solution 20 - Github
- Control panel
- Credential manager
- Look for options webcredentials and windows credentials
- in either one you will find github credentials fix it with correct credentials
- open new instance of git bash you should be able to perform your git commands.
This worked for me, I was able to pull and push into my remote repo.
Solution 21 - Github
I had the same issue. And I solved it by changing the remote branch's path from https://github.com/YourName/RepoName
to [email protected]:YourName/RepoName.git
in the repo's settings of the client app.
Solution 22 - Github
I'm constantly running into this problem.
Make sure you set git --config user.name "
Solution 23 - Github
I just disable the Two-factor authentication and try again. It works for me.
Solution 24 - Github
Since you probably want to keep 2FA enabled for your account, you can set up a ssh key and that way you won't need to type your Github credentials every time you want to push work to Github.
You can find all the ssh setup steps in the documentation. First, make sure you don't currently have any ssh keys (id_rsa.pub, etc.) with $ ls -al ~/.ssh
Solution 25 - Github
There is a issue on Windows using cmd-Greetings
There is a issue on Windows using cmd-Greetings who will not let you clone private repositories. Remove that cmd-greeting described in this documentation (keyword Command Processor
):
I can confirm that other clients like SourceTree, GitKraken, Tower and TortoiseGit affected to this issue too.
Solution 26 - Github
I fixed my issue by installing GitHub CLI and running gh auth login
Solution 27 - Github
one of the best and easiest way
- just disabled to two-way of authentication on github
- go to control panel--> windows credentials--> click on add generic credentials
just manually you have to type add URL of Github: hhtps://www.github.com username: your username password: your password then save to it
3)while using a git push command so, you have to need to generate a token on Github go back to again, on Github > setting> developer setting> generate token
hope this would be helpful....
Solution 28 - Github
This solution worked for me:
- open Control Panel
- Go to Credential Manager
- Click Window Credentials
- In Generic Credential section ,there would be git url, update username and password
- Restart Git Bash and try for clone