{"record":{"id":"157871705ebe917b","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-add-git-configuration-entry-name","errorCode":null,"errorMessage":"Failed to add Git configuration entry '{name}'","messagePattern":"Failed to add Git configuration entry '(.+?)'","errorType":"exception","errorClass":"Trace2Exception","httpStatus":null,"severity":"error","filePath":"src/Core/GitConfiguration.cs","lineNumber":620,"sourceCode":"\n        public void Add(GitConfigurationLevel level, string name, string value)\n        {\n            EnsureSpecificLevel(level);\n\n            string levelArg = GetLevelFilterArg(level);\n            using (ChildProcess git = _git.CreateProcess($\"config {levelArg} --add {QuoteCmdArg(name)} {QuoteCmdArg(value)}\"))\n            {\n                git.Start(Trace2ProcessClass.Git);\n                git.WaitForExit();\n\n                switch (git.ExitCode)\n                {\n                    case 0: // OK\n                        InvalidateCache();\n                        break;\n                    default:\n                        _trace.WriteLine($\"Failed to add config entry '{name}' with value '{value}' (exit={git.ExitCode}, level={level})\");\n                        throw GitProcess.CreateGitException(git, $\"Failed to add Git configuration entry '{name}'\");\n                }\n            }\n        }\n\n        public void Unset(GitConfigurationLevel level, string name)\n        {\n            EnsureSpecificLevel(level);\n\n            string levelArg = GetLevelFilterArg(level);\n            using (ChildProcess git = _git.CreateProcess($\"config {levelArg} --unset {QuoteCmdArg(name)}\"))\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","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/GitConfiguration.cs#L602-L638","documentation":"Thrown by GitConfiguration.Add when `git config --add <name> <value>` exits non-zero. Add appends a multi-valued entry; failure usually means the key name is invalid or the config file cannot be written.","triggerScenarios":"Calling Add(level, name, value) with a malformed key name, or when the underlying `git config --add` fails because the config file is read-only, locked, or the level's file cannot be created.","commonSituations":"Adding to a local config in a non-repository directory; invalid key like 'remoteorigin' without dots; enterprise environments where config files are managed read-only by policy.","solutions":["Use a valid 'section.key' (or 'section.subsection.key') name","Ensure you are in a valid repository when using the Local level and the file is writable","Run `git config --add <level> <name> <value>` manually to reproduce and see git's stderr","Check for file locks or read-only attributes on the config file"],"exampleFix":"// before\nconfig.Add(level, \"fetchmirror\", \"...\"); // throws: no section\n// after\nconfig.Add(level, \"remote.origin.mirror\", \"true\"); // valid key","handlingStrategy":"validation","validationCode":"static bool IsValidConfigKey(string name) {\n    var parts = name.Split('.');\n    return parts.Length >= 2 && parts.All(p => p.Length > 0);\n}\n// plus: ensure working dir is a repository when level == Local","typeGuard":null,"tryCatchPattern":"try { cfg.Add(level, name, value); }\ncatch (GitException ex) { log.Error($\"Add '{name}' failed: {ex.Message}\"); }","preventionTips":["Confirm a valid multi-dot key name before Add","Ensure Local-level writes happen inside a real repository","Watch for policy-managed read-only global configs in enterprise setups","Retry once after transient file locks"],"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-16T09:17:16.951Z"}