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

Failed to unset all Git configuration multi-valued entries

Error message

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

What it means

Thrown when `git config --unset-all <name> <valueRegex>` exits with an unexpected code. Exit 0 and exit 5 (nothing matched) are both treated as success; this error fires on invalid key/regex syntax or when git cannot rewrite the config file.

Solutions

  1. Test with `git config --unset-all <name> <valueRegex>` manually to capture git's error
  2. Validate key format ('section.key') and fix regex escaping in valueRegex
  3. Check write permissions/locks on the config file
  4. Treat 'nothing to unset' as fine — exit 5 does not throw, so this error means a genuine failure

Example fix

// before
config.UnsetAll(level, "remote.origin.url", "https://*"); // '*' quantifier error
// after
config.UnsetAll(level, "remote.origin.url", "https://.*"); // valid regex
Defensive patterns

Strategy: try-catch

Validate before calling

static bool IsValidPosixRegex(string pattern) {
    try { _ = new System.Text.RegularExpressions.Regex(pattern); return true; }
    catch (ArgumentException) { return false; }
}
// and static bool IsValidConfigKey(string n) => n.Split('.').Length >= 2;

Try / catch

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

Prevention

When it happens

Trigger: Calling UnsetAll(level, name, valueRegex) with an invalid key name, a malformed value regex, or when the config file is read-only/locked/malformed and cannot be rewritten.

Common situations: Bulk-removing mirror URLs with a regex containing unescaped special chars; removing an unknown key whose name is malformed; enterprise-managed read-only global .gitconfig.

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/af7331f0609cd102. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/GitConfiguration.cs:797

            if (valueRegex != null)
            {
                gitArgs += $" {QuoteCmdArg(valueRegex)}";
            }

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

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

        private static void EnsureSpecificLevel(GitConfigurationLevel level)
        {
            if (level == GitConfigurationLevel.All)
            {
                throw new InvalidOperationException("Must have a specific configuration level filter to modify values.");
            }
        }

        private static string GetLevelFilterArg(GitConfigurationLevel level)
        {
            switch (level)
            {
                case GitConfigurationLevel.System:
                    return "--system";

View on GitHub (pinned to e8ce762cd0)