{"record":{"id":"af7331f0609cd102","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-unset-all-git-configuration-multi-valued","errorCode":null,"errorMessage":"Failed to unset all Git configuration multi-valued entries '{name}'","messagePattern":"Failed to unset all Git configuration multi-valued entries '(.+?)'","errorType":"exception","errorClass":"Trace2Exception","httpStatus":null,"severity":"error","filePath":"src/Core/GitConfiguration.cs","lineNumber":797,"sourceCode":"            if (valueRegex != null)\n            {\n                gitArgs += $\" {QuoteCmdArg(valueRegex)}\";\n            }\n\n            using (ChildProcess git = _git.CreateProcess(gitArgs))\n            {\n                git.Start(Trace2ProcessClass.Git);\n                git.WaitForExit();\n\n                switch (git.ExitCode)\n                {\n                    case 0: // OK\n                    case 5: // Trying to unset a value that does not exist\n                        InvalidateCache();\n                        break;\n                    default:\n                        _trace.WriteLine($\"Failed to unset all multivar '{name}' with value regex '{valueRegex}' (exit={git.ExitCode}, level={level})\");\n                        throw GitProcess.CreateGitException(git, $\"Failed to unset all Git configuration multi-valued entries '{name}'\");\n                }\n            }\n        }\n\n        private static void EnsureSpecificLevel(GitConfigurationLevel level)\n        {\n            if (level == GitConfigurationLevel.All)\n            {\n                throw new InvalidOperationException(\"Must have a specific configuration level filter to modify values.\");\n            }\n        }\n\n        private static string GetLevelFilterArg(GitConfigurationLevel level)\n        {\n            switch (level)\n            {\n                case GitConfigurationLevel.System:\n                    return \"--system\";","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/GitConfiguration.cs#L779-L815","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Test with `git config --unset-all <name> <valueRegex>` manually to capture git's error","Validate key format ('section.key') and fix regex escaping in valueRegex","Check write permissions/locks on the config file","Treat 'nothing to unset' as fine — exit 5 does not throw, so this error means a genuine failure"],"exampleFix":"// before\nconfig.UnsetAll(level, \"remote.origin.url\", \"https://*\"); // '*' quantifier error\n// after\nconfig.UnsetAll(level, \"remote.origin.url\", \"https://.*\"); // valid regex","handlingStrategy":"try-catch","validationCode":"static bool IsValidPosixRegex(string pattern) {\n    try { _ = new System.Text.RegularExpressions.Regex(pattern); return true; }\n    catch (ArgumentException) { return false; }\n}\n// and static bool IsValidConfigKey(string n) => n.Split('.').Length >= 2;","typeGuard":null,"tryCatchPattern":"try { cfg.UnsetAll(level, name, valueRegex); }\ncatch (GitException ex) { log.Error($\"UnsetAll '{name}' failed: {ex.Message}\"); }","preventionTips":["Remember 'nothing matched' (exit 5) does not throw — a throw means bad syntax or unwritable file","Escape regex metacharacters when patterns are built from user input","Check config write permissions before bulk unset operations","Test the exact command with plain git first when regexes come from external sources"],"tags":["git","config","write"],"backgroundTag":"git-command-failed","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T14:17:13.074Z"}