// How-to · Let agents run safely
Undo agent changes: git checkpoints, worktrees and reflog
git is the most reliable undo button for agents: one branch or worktree per task, frequent commits, and reflog to recover committed states after a mistake.
verified 2026-10-102 official sources
Scenario: Let agents run safely →
Symptoms
- The agent broke the code and you want to go back a few steps
- Commits “disappeared” after
git reset --hard
Common causes
- Changes were not committed, or several agents overwrite each other in one working directory
How to fix
- Give each agent task its own branch, or its own worktree with
git worktree add ../task-x -b task-x - Have the agent commit after each working step so you can roll back gradually
- After a mistaken
reset --hard, rungit reflogto find the earlier commit andgit reset --hard <commit>or create a branch from it - git cannot recover changes that were never committed or staged, so commit before starting
Official references
Compiled from official documentation and public discussions on 2026-10-10; not yet reproduced in our own environment. Follow the official docs if they differ.