How do I disable git's credential helper for a single repository?

With git 2.9 (June 2016), this (helper = ) will actually work!

See commit 2432137 (26 Feb 2016) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 1b68962, 03 Apr 2016)

The credential.helper configuration variable is cumulative and there is no good way to override it from the command line.
As a special case, giving an empty string as its value now serves as the signal to clear the values specified in various files.

credential: let empty credential specs reset helper list

Since the credential.helper key is a multi-valued config list, there's no way to "unset" a helper once it's been set. So if your system /etc/gitconfig sets one, you can never avoid running it, but only add your own helpers on top.

Since an empty value for credential.helper is nonsensical (it would just try to run "git-credential-"), we can assume nobody is using it. Let's define it to reset the helper list, letting you override lower-priority instances which have come before.


Even more convenient: With Git 2.26 (Q1 2020), this override applies even for any value.

See commit 46fd7b3, commit 82eb249, commit 588c70e, commit 732f934, commit 3fa0e04 (20 Feb 2020) by brian m. carlson (``).
(Merged by Junio C Hamano -- gitster -- in commit 2cbb058, 05 Mar 2020)

credential: use the last matching username in the config

Signed-off-by: brian m. carlson

Everywhere else in the codebase, we use the rule that the last matching configuration option is the one that takes effect.

This is helpful because it allows more specific configuration settings (e.g., per-repo configuration) to override less specific settings (e.g., per-user configuration).

However, in the credential code, we didn't honor this setting, and instead picked the first setting we had, and stuck with it.

This was likely to ensure we picked the value from the URL, which we want to honor over the configuration.

It's possible to do both, though, so let's check if the value is the one we've gotten over our protocol connection, which if present will have come from the URL, and keep it if so.

Otherwise, let's overwrite the value with the latest version we've got from the configuration, so we keep the last configuration value.


What I've tried, and had worked well was:

$ git config --system --unset credential.helper

But in order to that works fine, I had to set git-bash.exe with Administrator rights.

Unfortunately, I think this is a global variable. You should test and see if it works for single repositories.

Good luck


A config variable that is set to an empty string is not the same as an unset variable. It is not possible to force a variable to be unset in .git/config when it is already set in ~/.gitconfig.

Additionally credential.helper is one of these variables where multiple values are used, and in such cases the values are aggregated from all read config files.

So basically your options seem to be:

  • either do not use credential.helper in ~/.gitconfig; set the store helper only for the repositories where you want it, either in their .git/config, or in ~/.gitconfig by specifying the repo URLs, eg.

    [credential "https://specific.example.com/repo.git"]
    helper = store
    
  • or implement your own helper that does nothing for a set of configured repositories and delegates to git credential-store for the rest.

Tags:

Git