eyaltoledano/claude-task-master · warning

Not in a git repository, cannot auto-switch tags

Error message

Not in a git repository, cannot auto-switch tags

What it means

autoSwitchTagForBranch integrates tag switching with git branches. Before doing anything it checks isGitRepository(projectRoot); if the working directory is not inside a git repository it logs this warning and returns { switched: false, reason: 'not_git_repo' }. Auto-switching is meaningless without branches, so the operation is safely skipped.

Source

Thrown at scripts/modules/task-manager/tag-management.js:1485

		getCurrentBranch,
		isGitRepository,
		sanitizeBranchNameForTag,
		isValidBranchForTag
	} = await import('../utils/git-utils.js');

	// Create a consistent logFn object regardless of context
	const logFn = mcpLog || {
		info: (...args) => log('info', ...args),
		warn: (...args) => log('warn', ...args),
		error: (...args) => log('error', ...args),
		debug: (...args) => log('debug', ...args),
		success: (...args) => log('success', ...args)
	};

	try {
		// Check if we're in a git repository
		if (!(await isGitRepository(projectRoot))) {
			logFn.warn('Not in a git repository, cannot auto-switch tags');
			return { switched: false, reason: 'not_git_repo' };
		}

		// Get current git branch
		const currentBranch = await getCurrentBranch(projectRoot);
		if (!currentBranch) {
			logFn.warn('Could not determine current git branch');
			return { switched: false, reason: 'no_current_branch' };
		}

		logFn.info(`Current git branch: ${currentBranch}`);

		// Check if branch is valid for tag creation
		if (!isValidBranchForTag(currentBranch)) {
			logFn.info(`Branch "${currentBranch}" is not suitable for tag creation`);
			return {
				switched: false,
				reason: 'invalid_branch_for_tag',

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Run 'git init' in the project root (and make an initial commit) if branch-based tagging is desired.
  2. Run the command from within the actual repository root, not a non-repo copy of the files.
  3. If you don't need auto-switching, ignore the warning or disable the git workflow option.
  4. In CI, ensure the checkout step (e.g. actions/checkout) runs so .git exists before invoking task-master.

Example fix

// before (shell)
npx task-master list  # run in extracted zip, no git
// after
git init && git add -A && git commit -m init
npx task-master list
Defensive patterns

Strategy: fallback

Validate before calling

const { execSync } = require('child_process');
function inGitRepo(root) {
  try { execSync('git rev-parse --is-inside-work-tree', { cwd: root, stdio: 'ignore' }); return true; }
  catch { return false; }
}
if (!inGitRepo(projectRoot)) console.warn('Skipping tag auto-switch: not a git repo');

Type guard

function isRepoRoot(root) {
  return require('fs').existsSync(require('path').join(root, '.git'));
}

Try / catch

try {
  const r = await autoSwitchTagForBranch(projectRoot, opts);
  if (r.reason === 'not_git_repo') {
    // proceed without tag switching
  }
} catch (e) { /* handle */ }

Prevention

When it happens

Trigger: Invoking autoSwitchTagForBranch (directly or via task flows that call it, e.g. after task operations with useGitWorkflow enabled) while projectRoot is outside any .git directory, or when git init was never run.

Common situations: Running task-master in a freshly downloaded folder without git init; CI workspaces that copy files without the .git directory; Docker images that omit git metadata; passing a subdirectory or parent path that is not a repo root.

Related errors


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