2

I have generated a new access token, and I tried to clone a repo but got that error: Github remote: Invalid username or password. fatal: Authentication failed I tried multiple trials, I set the github token as: git config --global github.token mytoken and I opened my .gitconfig file to check it and found it correctly:

[user]
    name = {github user}
    email = {github email}
[github]
    token = {new token}
    
[credential]
    helper = store
[core]
    editor = vim

I even tried git config --global --unset-all user.password and I was expecting that it will ask me for te username and password (in this case, I would add token), but it didn't ask about neither the username nor password, and still when I try cloning I get the same error.

Is there anything I am missing that would help or something I need to check please?

Mee
  • 1,413
  • 5
  • 24
  • 40
  • 1
    I don't think anything looks for a `github.token` setting. You're using `credential.helper = store` here so your https authentication user name and password are stored (unprotected!) in whatever file you specify, with the default being `~/.git-credentials`. You can edit this file with any editor (although you're not supposed to), or remove it. See [the documentation](https://git-scm.com/docs/git-credential-store). – torek Mar 24 '22 at 14:54
  • 1
    See also [this answer from VonC](https://stackoverflow.com/a/68374333/1256452). Related: [clear all git credentials from the CLI on git for windows' bash](https://stackoverflow.com/q/57981960/1256452). – torek Mar 24 '22 at 14:57
  • I already removed the file ```~/.git-credentials```, all these steps are after deletion of this file and still no luck – Mee Mar 24 '22 at 15:33
  • What OS are you on? You might want to use the osx keychain credential helper on OSX, or the Windows credential manager on Windows. Do you have any other credential helpers enabled? – torek Mar 24 '22 at 15:38
  • I am using windows – Mee Mar 24 '22 at 15:40
  • In that case, you probably want to see [Adding Git credentials on Windows](https://stackoverflow.com/q/46878457/1256452) and its linked questions. (I don't use Windows, and I don't use https if I can avoid it: I prefer ssh for connecting to GitHub.) – torek Mar 24 '22 at 15:42

2 Answers2

2

Git has a configuration duplication issue, try replacing all configs with the new token using the following command:

git config --global --replace-all remote.origin.url https://<username>:<token>@github.com/<username>/<repo_name>.git
Omar
  • 300
  • 5
  • 14
1

The issue was resolved by:

1- Control Panel

2-Credential Manager

3-Click Window Credentials

4- In Generic Credential section ,there would be git url, update username and password (in that case password is the new token)

5-Restart Git Bash and try for clone

Mee
  • 1,413
  • 5
  • 24
  • 40