eyaltoledano/claude-task-master · error

no staged changes to commit

Error message

no staged changes to commit

What it means

createCommit() checks hasStagedChanges() before committing and throws this static message when the index has nothing staged and options.allowEmpty is not set. Git itself would reject an empty commit; the adapter surfaces it as a friendly error early. Only changes added to the index count — modified-but-unstaged files do not.

Source

Thrown at packages/tm-core/src/modules/git/adapters/git-adapter.ts:587

		} = {}
	): Promise<void> {
		// Check if on default branch and enforcement is requested
		if (options.enforceNonDefaultBranch && !options.force) {
			const currentBranch = await this.getCurrentBranch();
			const defaultBranches = ['main', 'master', 'develop'];
			if (defaultBranches.includes(currentBranch)) {
				throw new Error(
					`cannot commit to default branch: ${currentBranch}\n` +
						`Please create a feature branch or use force option.`
				);
			}
		}

		// Check for staged changes unless allowEmpty
		if (!options.allowEmpty) {
			const hasStaged = await this.hasStagedChanges();
			if (!hasStaged) {
				throw new Error('no staged changes to commit');
			}
		}

		// Build commit arguments
		const commitArgs: string[] = ['commit'];

		// Add message
		commitArgs.push('-m', message);

		// Add metadata as separate commit message lines
		if (options.metadata) {
			commitArgs.push('-m', ''); // Empty line separator
			for (const [key, value] of Object.entries(options.metadata)) {
				commitArgs.push('-m', `[${key}:${value}]`);
			}
		}

		// Add flags

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Stage changes before committing: git add -A (or stage specific files), then retry.
  2. Pass { allowEmpty: true } if an empty commit is intentional (e.g. triggering CI).
  3. Verify with hasStagedChanges() before committing and stage programmatically if false.
  4. Check `git status` — modified-but-unstaged files still count as 'nothing staged'.

Example fix

// before
await git.createCommit('msg'); // throws if nothing staged
// after
if (!(await git.hasStagedChanges())) {
  await git.git.add('./*'); // or stage intended files
}
await git.createCommit('msg');
Defensive patterns

Strategy: validation

Validate before calling

if (!(await git.hasStagedChanges()) && !allowEmpty) {
  // stage files here or abort with a clear message
}

Try / catch

try {
  await git.createCommit('msg');
} catch (e) {
  if (e instanceof Error && e.message === 'no staged changes to commit') {
    console.error('Stage files first: git add <files>');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling createCommit(message) when nothing has been git-added: files modified but not staged, all changes unstaged, or the working tree is completely clean — without { allowEmpty: true }.

Common situations: Automation forgetting to stage files before committing; assuming the adapter auto-stages (it does not); expecting a --allow-empty style commit without passing allowEmpty; a hook or earlier step already consumed the staged changes.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/5c872322397cc81c. Report an issue: GitHub.