eyaltoledano/claude-task-master · warning
Could not determine current git branch
Error message
Could not determine current git branch
What it means
After confirming the directory is a git repository, autoSwitchTagForBranch calls getCurrentBranch(projectRoot). If that returns a falsy value (e.g. detached HEAD with no branch name resolution, or git command failure), it warns 'Could not determine current git branch' and returns { switched: false, reason: 'no_current_branch' }.
Source
Thrown at scripts/modules/task-manager/tag-management.js:1492
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',
branchName: currentBranch
};
}
// Check if there's already a mapping for this branch
let tagName = await getTagForBranch(projectRoot, currentBranch);
View on GitHub (pinned to c0c98d367c)
Solutions
- Create and switch to a named branch: 'git switch -c main' (or checkout an existing branch) so HEAD resolves.
- Make an initial commit if the repo is empty — branches don't exist before the first commit.
- Ensure git is installed and on PATH in the execution environment.
- In CI, configure the checkout action to fetch the branch (e.g. set ref to branch name instead of SHA) to avoid detached HEAD.
- Inspect .git/HEAD for corruption and repair or re-clone if needed.
Example fix
// before (CI step pinned to SHA => detached HEAD)
- uses: actions/checkout@v4
with: { ref: ${{ github.sha }} }
// after
- uses: actions/checkout@v4
with: { ref: ${{ github.ref_name }} } Defensive patterns
Strategy: validation
Validate before calling
const { execSync } = require('child_process');
function currentBranch(root) {
try {
return execSync('git rev-parse --abbrev-ref HEAD', { cwd: root })
.toString().trim();
} catch { return null; }
}
if (!currentBranch(projectRoot)) throw new Error('No current branch; create one with git switch -c main'); Type guard
function hasNamedBranch(root) {
const b = currentBranch(root);
return typeof b === 'string' && b.length > 0 && b !== 'HEAD';
} Try / catch
const r = await autoSwitchTagForBranch(projectRoot, opts);
if (r.reason === 'no_current_branch') {
// e.g. detached HEAD in CI — pin to a branch or skip switching
} Prevention
- Avoid detached HEAD states; checkout branches by name in CI.
- Make an initial commit before relying on branch-based features.
- Ensure git is installed and on PATH.
- Verify with 'git branch --show-current' before running.
When it happens
Trigger: Calling autoSwitchTagForBranch in a repo where the current branch cannot be resolved: detached HEAD state, empty repo with no initial commit, corrupted .git/HEAD, or git executable unavailable to the spawned command.
Common situations: CI checkouts pinned to a commit SHA (detached HEAD); brand-new repos with zero commits; environments where git is not installed or not on PATH; worktrees with unusual HEAD configuration.
Related errors
- Git is not installed or not accessible: ${errorMessage}
- currently on default branch: ${currentBranch} Please create
- NOT_GIT_REPO
- Not in a git repository, cannot auto-switch tags
- Failed to fetch tasks from any tag. First error: ${failedTag
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/872711caf728f03b.
Report an issue: GitHub.