abhigyanpatwari/GitNexus · error
Refusing to update : local changes detected. Set…
Error message
Refusing to update ${safeTarget}: local changes detected. Set overwrite_local_changes: true to overwrite them. What it means
During a pull/update, cloneOrPull runs 'git status --porcelain' in the existing target; if the output is non-empty the working tree has local modifications, and the update is refused rather than silently clobbered. The error tells you to opt in explicitly with overwrite_local_changes: true. It protects uncommitted user work in the clone.
Solutions
- Commit or discard the local changes in the target repo, then retry the sync.
- Pass overwrite_local_changes: true in the cloneOrPull options if the changes are disposable.
- Move/stash the changes (git stash) or copy them aside before re-running the sync.
- Clean untracked files (git clean -fd) if they are the trigger and are not needed.
Example fix
// before
await cloneOrPull({ url, targetDir });
// after (changes are intentionally disposable)
await cloneOrPull({ url, targetDir, overwrite_local_changes: true }); Defensive patterns
Strategy: try-catch
Validate before calling
const { stdout } = await exec('git status --porcelain', { cwd: targetDir });
if (stdout.trim()) {
console.warn('target has local changes; commit, stash, or set overwrite_local_changes: true');
}
await cloneOrPull({ url, targetDir, overwrite_local_changes: stdout.trim() ? true : false }); Try / catch
try {
await cloneOrPull(opts);
} catch (err) {
if ((err as Error).message.includes('local changes detected')) {
// surface to operator instead of silently overwriting
throw new Error(`Sync blocked: ${opts.targetDir} has uncommitted work. Resolve or set overwrite_local_changes.`, { cause: err });
}
throw err;
} Prevention
- Never edit auto-synced clones directly; work in separate worktrees.
- Add the clone dir to .gitignore hygiene so generated files do not accumulate as untracked changes.
- Run git status before scheduled syncs and alert instead of force-overwriting.
- Only set overwrite_local_changes: true after confirming the changes are disposable.
When it happens
Trigger: Calling cloneOrPull for a repo whose targetDir already exists as a git repo with uncommitted modifications or untracked files, without overwrite_local_changes: true.
Common situations: A developer edited files inside the auto-synced clone; build artifacts or generated files left untracked in the target; a crashed previous run left partial edits; hotfixes applied directly in the synced checkout.
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
- Branch " " is not indexed for " ". Indexed branches: . The…
- Clone failed and partial checkout could not be quarantined
- Clone target already exists but is not a git repository
- Clone target basename must match repository name
- Clone target must be a subdirectory of
AI-assisted analysis of abhigyanpatwari/GitNexus@ac9a4e9abd (2026-09-15).
Data as JSON: /api/errors/f914338c929507e0.
Report an issue: GitHub.
Appendix: source
Thrown at gitnexus/src/server/git-clone.ts:607
// "Already there" is a named-branch match OR a detached HEAD whose SHA
// equals `branch` / `origin/<branch>` (tag / SHA pin). A missing ref
// falls through to the switch path, which still refuses a dirty tree.
//
// Same-named-branch update uses the heads/ → remotes/ fetch refspec plus
// `checkout -B <branch> origin/<branch>`, never `pull origin <user-string>`
// (a leading `+` would otherwise be a force-fetch). Only
// `remote.origin.url` is verified above; `branch.<name>.remote` /
// `.merge` are not, so an implicit-upstream pull can update a different
// ref while the job still carries this branch (#3199 review).
const requestedRefMatch = options?.branch
? await matchRequestedRef(runGitImpl, safeTarget, options.branch, gitOpts)
: undefined;
if (options?.branch && !requestedRefMatch) {
if (!options.overwriteLocalChanges) {
const status = await runGitImpl(['status', '--porcelain'], safeTarget, gitOpts);
if (status.trim()) {
throw new Error(
`Refusing to update ${safeTarget}: local changes detected. Set overwrite_local_changes: true to overwrite them.`,
);
}
}
await runGitImpl(
['fetch', '--depth', '1', 'origin', branchFetchRefspec(options.branch)],
safeTarget,
gitOpts,
);
await runGitImpl(
[
'checkout',
...(options.overwriteLocalChanges ? ['--force'] : []),
'-B',
options.branch,
`origin/${options.branch}`,
],
safeTarget,View on GitHub (pinned to ac9a4e9abd)