xai-org/grok-build · error
working tree is not clean; commit or discard changes before
Error message
working tree is not clean; commit or discard changes before syncing the base
What it means
Sync-base checks `git status --porcelain` and refuses to run when the working tree is dirty, because merging a new base on top of uncommitted changes risks conflicts and data loss. This guard runs after the branch and merge-state checks.
Source
Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:3041
)
}
if abort {
let (_ok, out) = git_cli_raw_mut(git_root, &["merge", "--abort"]).await?;
anyhow::ensure!(
!merge_in_progress(git_root).await?,
"merge --abort failed: {out}"
);
return Ok(GitSyncBaseResult {
outcome: GitSyncBaseOutcome::Aborted,
});
}
ensure_on_branch(git_root, expected_branch).await?;
anyhow::ensure!(
!merge_in_progress(git_root).await?,
"a merge is already in progress; resolve it or call again with abort"
);
let dirty = git_cli(git_root, &["status", "--porcelain"]).await?;
anyhow::ensure!(
dirty.is_empty(),
"working tree is not clean; commit or discard changes before syncing the base"
);
let base = base_ref.unwrap_or("HEAD");
let (fetched, fetch_out) = git_cli_raw_mut(git_root, &["fetch", "origin", base]).await?;
anyhow::ensure!(fetched, "fetch of base ref '{base}' failed: {fetch_out}");
if git_cli_raw(
git_root,
&["merge-base", "--is-ancestor", "FETCH_HEAD", "HEAD"],
)
.await?
.0
{
return Ok(GitSyncBaseResult {
outcome: GitSyncBaseOutcome::UpToDate,
});
}
let (merged, merge_out) =View on GitHub (pinned to bc7f02eddd)
Solutions
- Commit the changes (`git add -A && git commit`) then retry sync-base
- Discard unneeded changes with `git checkout -- .` / `git clean -fd` if they are disposable
- Stash with `git stash -u`, run sync-base, then `git stash pop`
- Check `git status --porcelain` before invoking to confirm cleanliness
Example fix
// before sync_base(&git_root, req) // dirty tree // after git_cli(&git_root, &["add", "-A"]).await?; git_cli(&git_root, &["commit", "-m", "wip"]).await?; sync_base(&git_root, req)
Defensive patterns
Strategy: validation
Validate before calling
let out = Command::new("git").args(["status","--porcelain"]).current_dir(git_root).output()?;
if !out.stdout.is_empty() {
return Err("working tree dirty; commit, stash, or discard before sync".into());
} Prevention
- Commit or stash edits before invoking sync-base
- Add .gitignore entries for generated artifacts so they don't dirty the tree
- Run `git status --porcelain` as a pre-flight in automation
When it happens
Trigger: Calling sync-base with uncommitted modifications, staged changes, or untracked files present in the workspace.
Common situations: Agent edited files without committing before asking to rebase/sync onto the base branch; build artifacts or temp files left in the tree; a previous tool run left partial edits.
Related errors
- workspace is on '{current}', expected '{expected}'
- a merge is already in progress; resolve it or call again wit
- working tree is not clean; commit before merging to '{target
- git reset --hard {} failed: {}
- git clean {} failed: {}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/bcf2451dda7c802b.
Report an issue: GitHub.