pcottle/learnGitBranching · warning · CommandResult

git-error-staging

Error message

git-error-staging

What it means

git add throws CommandResult with git-error-staging when engine.changesModelEngaged is false — classic graph-only levels have no working directory, so there is nothing to stage. CommandResult (not GitError) means it's informational, ending the command gracefully.

Source

Thrown at src/js/git/commands.js:609

      }

      command.twoArgsImpliedHead(generalArgs);
      engine.branch(generalArgs[0], generalArgs[1]);
    }
  },

  add: {
    sc: /^ga($|\s)/,
    regex: /^git +add($|\s)/,
    description: 'Add file contents to the staging area',
    options: [
      '-A',
      '-u'
    ],
    execute: function(engine, command) {
      if (!engine.changesModelEngaged) {
        // classic graph-only levels have no working directory to stage
        throw new CommandResult({
          msg: intl.str('git-error-staging')
        });
      }
      var commandOptions = command.getOptionsMap();
      var generalArgs = command.getGeneralArgs();
      // '.', -A and -u all mean "stage everything"
      var stageAll = !!commandOptions['-A'] || !!commandOptions['-u'] ||
        generalArgs.indexOf('.') !== -1;
      engine.addFiles(stageAll ? null : generalArgs);
    }
  },

  restore: {
    regex: /^git +restore($|\s)/,
    description: 'Restore working tree files',
    options: [
      '--staged',
      '-S'

View on GitHub (pinned to 5b09d0ff96)

Solutions

  1. Skip git add in graph-only levels — git commit works directly
  2. Switch to a level that engages the working-directory model
  3. Check engine.changesModelEngaged before issuing staging commands

Example fix

// before
git add .; git commit -m 'x'   // graph-only level
// after
git commit -m 'x'
Defensive patterns

Strategy: validation

Validate before calling

if (!engine.changesModelEngaged) { skip('git add not available here'); return; }

Type guard

function stagingAvailable(engine) { return !!engine.changesModelEngaged; }

Prevention

When it happens

Trigger: Running git add in any classic graph-only level/sandbox (intro, rampup, etc.) where the changes model isn't engaged.

Common situations: Mixing commands from the staging tutorial into graph levels; muscle-memory typing git add before commits in the simulator.

Related errors


AI-assisted analysis of pcottle/learnGitBranching@5b09d0ff96 (2026-08-27). Data as JSON: /api/errors/d16e4625005e5392. Report an issue: GitHub.