21

I revoked my token for GitLab, how can I set the new token for cmd use?

When trying to push, this is the error I get:

remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab.com/myusername/repo.git'

The credential.helper is set to manager.

I tried to unset credential.helper, and then when I push it asked for the credentials, which will work when I supply them. If I re-set credential.helper to manager, it will raise the previous error again.

So, how can I set the new token?
(The preferred method would be from the cmd).

Thanks!

2 Answers 2

8

Here's a generic method that should work with all currently configured (and writable) credential helpers (and to be honest, I'm surprised git didn't do this automatically – it's supposed to):

  1. Run git credential reject (to use all configured helpers) or git credential-manager erase (to use the manager helper).

  2. Type in the following text:

    protocol=https
    host=gitlab.com
    path=/myusername/repo.git
    

    The main git credential tool also accepts a simpler version (but individual helpers do not):

    url=https://gitlab.com/myusername/repo.git
    
  3. At a blank line, press Ctrl+Z, Enter (Windows Console) or Ctrl+D (Linux, Cygwin, macOS...) to signal end-of-input.

  4. If you want, repeat with git credential fill or git credential-manager get to make sure the credentials cannot be retrieved anymore.

2
  • I already fixed it with my solution, but it seems that yours is the correct way, which I haven't found in my research. Thanks! Apr 18, 2018 at 14:33
  • Did not work on windows 10. Manually removing from windows credential manager did stackoverflow.com/a/53541774/429476 Aug 28, 2019 at 14:13
20

CMD

With cmdkey:

  1. Run cmdkey /list from the command line, and find your target.
  2. To update the password, run cmdkey /generic:$TARGET_NAME$ /user:$MYUSERNAME$ /pass and enter your password when prompted.
    • For example: cmdkey /generic:git:https://gitlab.com /user:myusername /pass
  3. Use the credential again - push to your git remote.

GUI

With Windows Credential Manager:

  1. From the start menu, search and open the Credential Manager.
    • Or, run control /name Microsoft.CredentialManager
  2. Go to the Windows Credentials section and find your relevant credential (e.g the git remote service, in this case - GitLab).
  3. Open the credentials details.
  4. Choose Edit
  5. Enter the new password.
  6. Save.
  7. Use the credential again - push to your git remote.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .