git-ecosystem/git-credential-manager · error · Trace2Exception

Failed to replace all Git configuration multi-valued entries

Error message

Failed to replace all Git configuration multi-valued entries '{name}'

What it means

Thrown when `git config --replace-all <name>` exits non-zero. ReplaceAll rewrites every values matching an optional value regex; failure typically means the key name is invalid, the value regex is malformed, or the config file cannot be written back.

Solutions

  1. Run `git config --replace-all <name> <valueRegex> <value>` manually to see git's error
  2. Validate the key name format and escape regex metacharacters in valueRegex
  3. Ensure the config file is writable and not locked by another process
  4. Fix any existing config parse errors before rewriting

Example fix

// before
config.ReplaceAll(level, "remote.origin.url", "*", newUrl); // '*' breaks git parsing
// after
config.ReplaceAll(level, "remote.origin.url", ".*", newUrl); // valid regex
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidConfigKey(string name) {
    var parts = name.Split('.');
    return parts.Length >= 2 && parts.All(p => p.Length > 0);
}
// use ".*" not "*" for match-all valueRegex

Try / catch

try { cfg.ReplaceAll(level, name, valueRegex, value); }
catch (GitException ex) { log.Error($"ReplaceAll '{name}' failed: {ex.Message}"); }

Prevention

When it happens

Trigger: Calling ReplaceAll(level, name, valueRegex, value) with an invalid key, a bad value regex, or when git cannot rewrite the target config (read-only, locked, malformed existing config).

Common situations: Replacing values for a misspelled key; regex with special characters that break git's parsing; config file locked by another git process or IDE.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/6c0ed4e9dc0952be. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/GitConfiguration.cs:768

            var gitArgs = $"config {levelArg} --replace-all {QuoteCmdArg(name)} {QuoteCmdArg(value)}";
            if (valueRegex != null)
            {
                gitArgs += $" {QuoteCmdArg(valueRegex)}";
            }

            using (ChildProcess git = _git.CreateProcess(gitArgs))
            {
                git.Start(Trace2ProcessClass.Git);
                git.WaitForExit();

                switch (git.ExitCode)
                {
                    case 0: // OK
                        InvalidateCache();
                        break;
                    default:
                        _trace.WriteLine($"Failed to replace all multivar '{name}' and value regex '{valueRegex}' with new value '{value}' (exit={git.ExitCode}, level={level})");
                        throw GitProcess.CreateGitException(git, $"Failed to replace all Git configuration multi-valued entries '{name}'");
                }
            }
        }

        public void UnsetAll(GitConfigurationLevel level, string name, string valueRegex)
        {
            EnsureSpecificLevel(level);

            string levelArg = GetLevelFilterArg(level);
            var gitArgs = $"config {levelArg} --unset-all {QuoteCmdArg(name)}";
            if (valueRegex != null)
            {
                gitArgs += $" {QuoteCmdArg(valueRegex)}";
            }

            using (ChildProcess git = _git.CreateProcess(gitArgs))
            {
                git.Start(Trace2ProcessClass.Git);

View on GitHub (pinned to e8ce762cd0)