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

Failed to unset Git configuration entry

Error message

Failed to unset Git configuration entry '{name}'

What it means

Thrown by GitConfiguration.Unset when `git config --unset <name>` exits with an unexpected code. Exit 0 and exit 5 (key/value does not exist) are treated as success, so this fires only on real failures: invalid key name or an unwritable config file (unset rewrites the file).

Solutions

  1. Confirm the key exists with `git config --get <name>`; remember exit 5 (missing) is tolerated, so this error implies something else
  2. Check write permissions on the config file — unset rewrites the whole file
  3. Fix any config parse errors (`git config --list`) that block rewriting
  4. Run `git config --unset <name>` manually to see the precise git error

Example fix

// before
config.Unset(level, "core.bare"); // throws if .git/config read-only
// after
try { config.Unset(level, "core.bare"); }
catch (GitException ex) { Log($"Could not unset core.bare: {ex.Message}"); }
Defensive patterns

Strategy: try-catch

Validate before calling

var probe = Process.Run("git", $"config --get {name}", workingDir);
// exit 1 = key absent (Unset tolerates); proceed only if probe.ExitCode == 0 or 1

Try / catch

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

Prevention

When it happens

Trigger: Calling Unset(level, name) with a malformed key or when git cannot rewrite the config file — read-only file, permission denied, or config parse error. Note exit 5 (nothing to unset) is NOT an error.

Common situations: Unsetting a key whose name has no section ('useremail' vs 'user.email'); .git/config owned by root or another user; config locked by another process; malformed config preventing rewrite.

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

Appendix: source

Thrown at src/Core/GitConfiguration.cs:643

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

            string levelArg = GetLevelFilterArg(level);
            using (ChildProcess git = _git.CreateProcess($"config {levelArg} --unset {QuoteCmdArg(name)}"))
            {
                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 config entry '{name}' (exit={git.ExitCode}, level={level})");
                        throw GitProcess.CreateGitException(git, $"Failed to unset Git configuration entry '{name}'");
                }
            }
        }

        public IEnumerable<string> GetAll(GitConfigurationLevel level, GitConfigurationType type, string name)
        {
            if (_useCache)
            {
                EnsureCacheLoaded(type);

                ConfigCache cache = _cache[type];
                if (cache.IsLoaded)
                {
                    var cachedValues = cache.GetAll(name, level);
                    foreach (var val in cachedValues)
                    {
                        yield return val;
                    }

View on GitHub (pinned to e8ce762cd0)