nikivdev/code · error
git {} failed: {}
Error message
git {} failed: {} What it means
Raised by a git helper in src/sync.rs when a git command fails and stderr/stdout produced a non-empty diagnostic. The message is `git <args> failed: <detail>` where detail is the trimmed combined stdout and stderr, giving the developer the actual git error text. This is the detail-bearing variant of the git failure error (918).
Source
Thrown at src/sync.rs:5135
let output = Command::new("git")
.current_dir(repo_root)
.args(args)
.output()
.context("failed to run git")?;
if output.status.success() {
return Ok(());
}
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let detail = format!("{}\n{}", stdout.trim(), stderr.trim())
.trim()
.to_string();
if detail.is_empty() {
bail!("git {} failed", args.join(" "));
}
bail!("git {} failed: {}", args.join(" "), detail);
}
fn restore_stash_result(
repo_root: &Path,
auto_stash_state: &AutoStashState,
allow_autofix: bool,
) -> Result<()> {
restore_stash_result_with_packet_dir(repo_root, auto_stash_state, allow_autofix, None)
}
fn restore_stash_result_with_packet_dir(
repo_root: &Path,
auto_stash_state: &AutoStashState,
allow_autofix: bool,
packet_dir_override: Option<&Path>,
) -> Result<()> {
if !auto_stash_state.stashed {
return Ok(());View on GitHub (pinned to a747e741ae)
Solutions
- Read the embedded `detail` text to identify the exact git error
- Run the failing `git <args>` command manually for full context
- Fix the underlying git issue (resolve conflicts, fetch missing refs, fix credentials) and retry the sync
- Check repo state with `git status` before re-running the sync
Example fix
// before: failing state, e.g. missing remote ref $ git fetch origin nonexistent-branch // error: git fetch origin nonexistent-branch failed: fatal: ... // after: use an existing ref $ git fetch origin main
Defensive patterns
Strategy: try-catch
Validate before calling
// preflight: clean, connected repo reduces git failures
let st = std::process::Command::new("git").args(["status", "--porcelain"]).output()?;
if !String::from_utf8_lossy(&st.stdout).is_empty() {
eprintln!("Working tree dirty; commit or stash before sync");
}
let remote = std::process::Command::new("git").args(["remote"]).output()?;
if String::from_utf8_lossy(&remote.stdout).is_empty() {
eprintln!("No git remote configured; fetch/pull-based sync will fail");
} Try / catch
match sync_result {
Err(e) if e.to_string().contains("failed: ") && e.to_string().starts_with("git ") => {
// detail after 'failed: ' is git's own stderr/stdout
eprintln!("{e}");
}
other => other?,
} Prevention
- Read the embedded detail line first; it usually names the exact git problem
- Ensure remotes and credentials are configured before syncing
- Keep the working tree clean to avoid operation refusals
- Run the failing git command manually for full diagnostics
When it happens
Trigger: A git invocation in the sync flow exits non-zero with at least one non-empty stdout/stderr line; that line becomes `detail` in the error message.
Common situations: Merge conflicts, missing refs/branches, detached or dirty state blocking operations, authentication failures on fetch/push, or bad arguments constructed by sync code.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- {} {} failed: {}
- git {} failed
- Unmerged files detected. Resolve them before syncing.
- Sync agent cleared raw conflicts for {} but validation and m
- Merge conflicts with {}. Run `:sync repair --packet {}` or r
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/6adf169f0980be7a.
Report an issue: GitHub.