Git Local Changes Would Be Overwritten: Safe Human and Coding-Agent Handoffs
Git refuses a merge, pull, or checkout when it would overwrite uncommitted work. In an AI-assisted repository, those changes may belong to a developer, a coding agent, or another automation process. The warning protects the handoff boundary.
Do not run a hard reset until ownership and value are known.
Inventory the work
git status --short --branch
git diff
git diff --staged
git ls-files --others --exclude-standard
Identify who created each change, which task it belongs to, and whether generated or untracked files matter. Save a patch outside the working tree when provenance is unclear:
git diff > ../handoff.patch
git diff --staged > ../handoff-staged.patch
Choose a reviewable preservation method
Commit on a task branch
Use this when the work is coherent enough to review. Stage only intended files and label the commit as work-in-progress if necessary.
Stash with context
Use a named stash for short-lived local work:
git stash push -u -m "agent handoff: task-123"
Inspect the stash before applying it elsewhere. Stashes are local and easy to orphan, so they are not a durable collaboration system.
Move to an isolated worktree
For parallel human/agent work, create separate branches and worktrees before edits begin. This avoids branch switches inside a workspace another actor owns.
After preserving changes
Fetch and integrate the target branch through the normal review workflow. Reapply the patch, commit, or stash and resolve conflicts with tests. Never assume generated code wins a conflict because it is newer.
Prevent unsafe handoffs
- Assign one owner per worktree.
- Require agents to report dirty status and changed files.
- Block branch switching with unreviewed changes.
- Use pull requests for agent-generated code.
- Keep unrelated tasks on separate branches.
- Run tests and inspect diffs before integration.
- Define who may discard generated output.
The Git foundation explains branches and worktrees. Connect this workflow to Coding Agents, GitHub Actions, and AI Testing & Evaluation.
The correct fix preserves evidence first, then integrates deliberately.