nikivdev/code · error
Failed to stash local changes: {}. Resolve the issue and re-
Error message
Failed to stash local changes: {}. Resolve the issue and re-run sync. What it means
During sync, when there are uncommitted local changes and the command has stash enabled, the code calls auto_stash_repo to stash them before proceeding. If the stash operation fails, it records 'stash failed' and throws 'Failed to stash local changes: {err}. Resolve the issue and re-run sync.', aborting the sync so the user can fix the working tree manually.
Source
Thrown at src/sync.rs:1451
let current = current.trim();
// Check for uncommitted changes
let status = git_capture(&["status", "--porcelain"])?;
let has_changes = !status.trim().is_empty();
if has_changes && !cmd.stash {
recorder.record("stash", "skipped (uncommitted changes without --stash)");
bail!("Uncommitted changes");
}
// Stash if needed
let mut auto_stash_state = AutoStashState::default();
if has_changes && cmd.stash {
sync_progressln!("Stashing local changes...");
auto_stash_state =
auto_stash_repo(repo_root_path, "f sync auto-stash").map_err(|err| {
recorder.record("stash", format!("stash failed: {}", err));
anyhow::anyhow!(
"Failed to stash local changes: {}. Resolve the issue and re-run sync.",
err
)
})?;
if !auto_stash_state.intent_to_add_paths.is_empty() {
sync_progressln!(
"Temporarily normalized {} intent-to-add path(s) before stashing.",
auto_stash_state.intent_to_add_paths.len()
);
recorder.record(
"stash",
format!(
"temporarily normalized {} intent-to-add path(s)",
auto_stash_state.intent_to_add_paths.len()
),
);
}
}View on GitHub (pinned to a747e741ae)
Solutions
- Read the underlying git error in the message and resolve it (e.g. remove a stale .git/index.lock after confirming no git process runs)
- Commit or manually stash/discarding changes with `git stash` / `git checkout -- .` before re-running sync
- Abort any in-progress merge/rebase (git merge --abort / git rebase --abort), then re-run sync
- Check .git permissions and disk space
Example fix
# before re-running sync rm -f .git/index.lock # only if no git process is running git stash -u # stash manually f sync # then re-run (with or without --stash)
Defensive patterns
Strategy: try-catch
Validate before calling
let status = std::process::Command::new("git").args(["status", "--porcelain"]).current_dir(repo_root).output()?;
let dirty = !status.stdout.is_empty();
if dirty {
// probe stash capability first
let probe = std::process::Command::new("git").args(["stash", "list"]).current_dir(repo_root).status()?;
if !probe.success() { eprintln!("git stash is currently broken; resolve before sync"); }
} Try / catch
match sync(cmd) {
Ok(()) => (),
Err(e) if e.to_string().contains("Failed to stash local changes") => {
eprintln!("{}", e); // includes underlying git error
eprintln!("hint: check for .git/index.lock, in-progress merge/rebase, then re-run sync");
}
Err(e) => return Err(e),
} Prevention
- Commit or stash intentionally before long-running syncs
- Remove stale .git/index.lock only when no git process is running
- Keep .git writable and watch disk space
- Avoid concurrent git operations in the same repo
When it happens
Trigger: Running sync with uncommitted changes while cmd.stash is true and auto_stash_repo fails — e.g. git cannot create a stash because of a lock file, conflicting index, untracked/ignored path issues, or intent-to-add entries that confuse `git stash`.
Common situations: Stale .git/index.lock from a crashed git process; merge/rebase in progress; corrupt stash ref; files with conflicting local modifications that stash refuses to handle; restricted permissions on .git.
Related errors
- failed to restore sync auto-stash automatically. Run `:sync
- failed to restore sync auto-stash automatically. Run `git st
- failed to restore sync auto-stash automatically: {} Run `:sy
- failed to restore sync auto-stash automatically: {} Run `git
- failed to stash working tree: {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/053d86dd771f2007.
Report an issue: GitHub.