yamadashy/repomix · error · RepomixError
Failed to get git diffs: ${error.message}
Error message
Failed to get git diffs: ${error.message} What it means
getGitDiffs runs `git diff` commands for the work tree and the staged area, then wraps any underlying failure (non-zero exit, git missing, not a repo) into a single RepomixError with this message. The original git error text is appended so the concrete cause (e.g. 'not a git repository', 'fatal: bad object') is visible in the message.
Source
Thrown at src/core/git/gitDiffHandle.ts:88
let gitDiffResult: GitDiffResult | undefined;
if (config.output.git?.includeDiffs) {
try {
// Use the first directory as the git repository root
// Usually this would be the root of the project
const gitRoot = rootDirs[0] || config.cwd;
const [workTreeDiffContent, stagedDiffContent] = await Promise.all([
deps.getWorkTreeDiff(gitRoot),
deps.getStagedDiff(gitRoot),
]);
gitDiffResult = {
workTreeDiffContent,
stagedDiffContent,
};
} catch (error) {
if (error instanceof Error) {
throw new RepomixError(`Failed to get git diffs: ${error.message}`);
}
}
}
return gitDiffResult;
};
View on GitHub (pinned to f465ad9093)
Solutions
- Run repomix inside a git repository (or `git init` / `git clone` the project) — `git diff` requires a repo.
- Install git and confirm `git --version` works in the same shell/environment.
- Read the appended cause in the message and fix that underlying git error (e.g. remove stale .git/index.lock, repair the repo).
Example fix
// before (plain zip download) npx repomix --include-diffs ./project-zip // after npm install -g repomix cd project-zip && git init && git add -A && git commit -m init npx repomix --include-diffs
Defensive patterns
Strategy: try-catch
Validate before calling
import { execFileSync } from 'node:child_process';
const isGitRepo = (dir: string) => {
try { execFileSync('git', ['-C', dir, 'rev-parse', '--is-inside-work-tree'], { stdio: 'ignore' }); return true; }
catch { return false; }
};
if (!isGitRepo(targetDir)) throw new Error('Target is not a git repository; diffs unavailable.'); Type guard
const isRepomixDiffError = (e: unknown): e is RepomixError & { message: string } =>
e instanceof RepomixError && e.message.startsWith('Failed to get git diffs:'); Try / catch
try {
const diffs = await getGitDiffs(...);
} catch (error) {
if (error instanceof RepomixError && error.message.startsWith('Failed to get git diffs:')) {
console.warn('Git diffs skipped:', error.message);
} else throw error;
} Prevention
- Ensure git is installed and on PATH in every environment (CI images, Docker) where diffs are requested.
- Only enable diff options when operating on a real git working tree.
- Pin a recent git version; very old gits lack flags the tool may rely on.
When it happens
Trigger: Calling getGitDiffs (or the --include-diffs code path) when the target directory is not a git repository, git is not installed or not on PATH, or the git diff subprocess exits non-zero for any reason.
Common situations: Running repomix on a plain directory that was downloaded as a zip (no .git); a stripped-down Docker/CI image without git; corrupted index or lock file making `git diff` fail.
Related errors
- Failed to get git logs: ${(error as Error).message}
- Git is not installed or not in the system PATH.
- Failed to clone repository: ${redactErrorMessage(error)}
- Invalid repository URL. URL contains potentially dangerous p
- Invalid URL protocol for '${redactUrl(url)}'. URL must start
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/c1438f2de9a42893.
Report an issue: GitHub.