0

Trying to figure out how to force command-line git to use Github token. If I clone repository with user name and token like git clone https://<user>:<mytoken>@git.web.com/organization/repositorythen everything works fine.

When I try to clone without the user name or token then the operation fails with an error:

remote: Password authentication is not available for Git Operations.
remote: You must use a personal access token or SSH key.

I would like to store that token somewhere so that I would not have to give it to git every time. Where should I store the token?

I tried to add token variable to a [user] section in .gitconfig file but it did not work.

Tried unsetting and setting (wincred) credential helper but that did not work either.

Optional Option
  • 1,521
  • 13
  • 33

1 Answers1

2

You should enable a credential manager, such as wincred, and then when Git prompts you for the username and password, enter the username and your token as the password. Git will then tell the credential helper to save the password in the system credential store, and future operations to the same server will reuse those credentials.

This is much more secure than using the token in the URL, because the system credential store is encrypted, whereas the file containing the URL is not.

It may be the case that you already have invalid credentials saved for that remote which are causing the failure; if so, see this answer for instructions on how to remove them so Git prompts you again, and then follow the steps above.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • I had credentials manager enabled already but did not know how to reset the credentials. When I deleted all git credentials using Credentials Manager UI then command-line git asked me for the user name, token and then it all worked fine. Thank you!. – Optional Option Nov 07 '19 at 18:21