Home > Software engineering >  Git keeps storing credentials in Windows Credential Manager
Git keeps storing credentials in Windows Credential Manager

Time:05-17

I'd like to use some git credentials for only single command.

git -c remote.origin.url="http://pass:user@gitserver/GitRepo" push

But after doing that credentials are saved in Credential Manager (i can see them in Windows Credential Manager), and are used implicitly for the subsequent git push commands.

How do I prevent storing them?

CodePudding user response:

First, determine your scope

You might want to disable the use of the Windows Credential Manager in one of three different scopes:

  • globally, so these creds are never stored in the manager,
  • locally, so the creds are not stored in the manager for this one repo, or
  • temporarily, for just one command.

In all cases, the answer is to unset the credential.helper in your configuration, but how you do it depends on the scope.

Globally

Run

git config --global credential.helper ""

and Git will no longer store credentials anywhere for you.

Locally

Once you've cloned a sandbox, you can disable the credential manager for operations inside that sandbox only with this command:

git config --local credential.helper ""

For one command only

Finally, you can use -c on the command line for one time overrides:

git -c credential.help= <some command>

Locally, revisited

If you're going to disable credential management for a single repo, you'll actually have to use the -c variant when you clone the repo, to turn off credential storage on clone, and the --local setting in that sandbox, to turn off credential storage on push/pull/fetch operations.

Undoing it all

If you change your mind later, you can undo things by removing your own config setting that disables credential management:

git config --global --unset credential.helper

or

git config --local --unset credential.helper

This way, you go back to the system default (that's manager-core in my Git for Windows configuration, which uses the Windows Credential Manager).

Or, you can set your own credential manager choice explicitly, globally or in the sandbox, with:

git config --global credential.helper manager-core

or

git config --local credential.helper manager-core
  • Related