← Problem log

Failed git step ran a reset in the wrong folder

Last verified Nov 13
By the Bluhook team · Published Nov 13, 2026
Version 1

1What happened

Quinn (AI agent, systems) hit it and fixed it. An engineering AI agent checked it.

Our systems AI agent wanted to test whether two pull requests would merge cleanly. The plan was to do it in a throwaway copy of the code (a git worktree), so the team's shared working copy would stay untouched.

The command chained the steps: fetch the code, step into the throwaway copy, then reset and merge. The fetch failed on a typo, so the step into the copy never ran. The reset and merge steps were joined with a plain semicolon, which runs the next step even after a failure. They ran in the shared copy instead.

The hard reset wiped one unsaved file edit there. Nothing was pushed.

Why it happened

The step into the copy depended on the fetch with &&. When the fetch failed, the cd was skipped, and the shell stayed in the shared folder. The steps after it didn't depend on the cd at all.

"Stop on first error" (set -e) would not have saved it. Bash ignores a failure inside an && or || chain under set -e, so the script keeps going.

What we tried first

We put the shared copy back on main with git reset --keep and checked that no local commits were left. Then we listed every file that changed in that minute. Only one tracked file was hit. The rest were files our agents write while they run, which a reset leaves alone.

We searched every agent transcript since the start of the month, and git's lost objects, for the wiped edit. It could not be recovered, so its owner redid it.

2What we did

  1. Step into the copy on its own line, and stop if that fails: cd <copy> || exit 1.

  2. Name the copy on every git command: git -C <copy> reset, git -C <copy> merge. A skipped cd then can't send a command to the wrong folder.

  3. One git write per command, so one failure can't fall through to the next write. The git reset documentation shows what a reset throws away, the git worktree documentation covers a separate working folder, and the git merge-tree documentation shows how to test a merge without touching files.

3How we checked

A second AI agent, from engineering, read the shared copy back: on main, 0 local commits, nothing lost beyond the one edit. The same merge test then ran the safe way in a throwaway copy. Both pull requests merged cleanly, in either order.

4Try it

If a command has to run in a certain folder, don't trust an earlier cd to still be in force. Name the folder in the command itself. And set -e won't catch a failure inside an && chain. A related git slip is when an agent removed a PR hold. Slips like this get caught by agent monitoring. It also helps to build a second path, so one failure cannot do harm alone.

gitAI agentscodePublished Nov 13

Keep reading

Free newsletter

Every practical lesson, the wins and the flops, goes into Robb on AI, a free email newsletter.

We'll add you to Robb on AI, our free newsletter on Substack. Unsubscribe anytime. Privacy policy

Robb Lejuwaan

Robb Lejuwaanwriter of Robb on AI

Find your #1 job for AI.

It's free, with no card and no call.