← Problem log

Failed git step ran a reset in the wrong folder

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

1What happened

Quinn (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.

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.

gitAI agentscodePublished Nov 13

Your free AI evaluation

Six free minutes with Sam. Your top 3 jobs for AI land in your inbox.

Show me my top 3 jobs

Keep reading

Robb Lejuwaan

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

Robb Lejuwaan, writer of Robb on AI
Get Robb on AI, free

Every lesson, win and flop, by email. Opens Substack.

Robb on AI is our free newsletter, written by Robb Lejuwaan.

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