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

后端 未结 5 1401
小蘑菇
小蘑菇 2020-11-27 18:02

If I have a credential helper set in my ~/.gitconfig, how can I disable/bypass it in a specific repo and use no credential helper?

I\'ve tried

5条回答
  •  感情败类
    2020-11-27 18:51

    In addition of 'git config credential.helper=' that I mention above with Git 2.9, you now (Git 2.13.x/Git 2.14, Q3 2017) can disable the credential helper just for one command (and not just for any command in a given repo)

    That means git -c credential.helper= clone /url/remote/repo now works.

    "git clone --config var=val" is a way to populate the per-repository configuration file of the new repository, but it did not work well when val is an empty string.
    This has been fixed.

    See commit db4eca1 (02 May 2017) by Jonathan Nieder (artagnon).
    (Merged by Junio C Hamano -- gitster -- in commit 883247c, 16 May 2017)

    clone: handle empty config values in -c

    "git clone --config" uses the following incantation to add an item to a config file, instead of replacing an existing value:

    git_config_set_multivar_gently(key, value, "^$", 0)
    

    As long as no existing value matches the regex ^$, that works as intended and adds to the config. When a value is empty, though, it replaces the existing value.

    Noticed while trying to set credential.helper during a clone to use a specific helper without inheriting from ~/.gitconfig and /etc/gitconfig.
    That is, I ran:

    git clone -c credential.helper= \
         -c credential.helper=myhelper \
         https://example.com/repo
    

    intending to produce the configuration:

    [credential]
         helper =
         helper = myhelper
    

    Without this patch, the 'helper =' line is not included and the credential helper from /etc/gitconfig gets used.


    Note that the documentation is now clearer with commit 515360f:

    credential doc: make multiple-helper behavior more prominent

    Git's configuration system works by reading multiple configuration files in order, from general to specific:

    • first, the system configuration /etc/gitconfig
    • then the user's configuration (~/.gitconfig or ~/.config/git/config)
    • then the repository configuration (.git/config)

    For single-valued configuration items, the latest value wins.
    For multi-valued configuration items, values accumulate in that order.

    For example, this allows setting a credential helper globally in ~/.gitconfig that git will try to use in all repositories, regardless of whether they additionally provide another helper.
    This is usually a nice thing --- e.g. I can install helpers to use my OS keychain and to cache credentials for a short period of time globally.

    Sometimes people want to be able to override an inherited setting.
    For the credential.helper setting, this is done by setting the configuration item to empty before giving it a new value.

提交回复
热议问题