← Blog

One step at a time

My AI coding agent pushed an unreviewed commit to the branch that runs my live site. What happened, how we fixed it, and the rule we work by now.

Written by
Naresh Kumar
Published
Reading time
3 min
Topic
Tech & AI

This week my AI coding agent pushed a version of my website I hadn’t approved to the branch that goes live.

Nothing broke, and nobody was hurt. But it was the exact thing I tell clients I guard against, so it’s worth writing down.

What happened

I build this site with an AI coding agent. After two days of redesign work, everything was ready on a separate branch, and I asked the agent to make it the main version of the site. My hosting publishes whatever is on main, so that step puts things live.

The agent ran several git commands in one go. The first one, switching to main, failed: an earlier session had left main checked out in a second working folder on my laptop, with an unfinished merge in it. That was also why I believed the redesign had already been merged. It hadn’t.

The commands after the failure kept running anyway. The last one pushed main, but it pushed the copy from that other folder. It carried an old commit I had never reviewed, straight to the branch my hosting publishes.

What happened Step 1, switch to main, failed because main was open in another folder, but the script kept going. Step 2, merge the redesign, did nothing. Step 3 pushed the other folder's main instead, so GitHub's main carried a commit I never reviewed, and Cloudflare publishes whatever is on main. 1. Switch to main Failed: main is open in another folder …but the script kept going 2. Merge the redesign Nothing happened: still on the old branch 3. Push main Pushed the other folder’s main instead GitHub: main Now carries a commit I never reviewed Cloudflare Publishes whatever is on main
One failed step, and everything after it carried on.

How we fixed it

The agent stopped as soon as it saw the result, told me exactly what had gone out, and listed what it had not touched. That mattered more to me than the mistake itself.

Then we fixed it carefully rather than quickly:

  • No rewriting history. The agent first tried to force main back. My own permission settings blocked it as destructive, and they were right to. Instead, we added one normal commit on top that made main exactly match the version I had reviewed, and checked that the files were identical.
  • Save before deleting. The extra folder held work in progress. Before removing anything, we saved it as a patch and checked that the patch applied cleanly.
  • One branch. We ended with a single main, on GitHub and on my laptop.

The rule now

One step at a time.

Anything that changes state, such as switching branches, committing, merging or pushing, runs as a single step. The agent reads the result, and stops at the first error. Before every push, it shows me two things:

git status -sb                 # which branch am I on, and is it in sync?
git log origin/main..HEAD      # exactly which commits will go out

If the second list holds anything I don’t recognise, nothing gets pushed.

The rule now Check where you are with git status. Run one step. If it did not work, stop and report. Before a push, list what will go out with git log origin/main..HEAD. If any commit is unrecognised, don't push. Otherwise push, then confirm everything is in sync. Check where you are git status -sb Run one step Did it work? No Stop and report Yes List what will go out git log origin/main..HEAD All commits recognised? No Don’t push Yes Push, then confirm in sync: git status -sb
Every state-changing step, checked before the next.

It’s slower by a few seconds. It would have saved us half an hour of careful clean-up.

Why this one stuck

I spent years in software testing, where you learn that most failures aren’t dramatic. They come from a small assumption nobody checked: the wrong environment, the wrong branch, the step that “obviously worked”.

Long rides taught me the same thing in a different way. On a climb you don’t think about the summit; you think about the next switchback, and you check the route at every junction, because one wrong turn early costs hours later.

Naresh with the loaded tandem on Teton Pass, snowy peaks behind

Teton Pass, Wyoming, 2024.

AI agents make it very easy to move fast, and most of the time that’s a gift. But speed amplifies whatever you skip. The agent didn’t need more intelligence here. It needed the same discipline I’d expect from any engineer on my team: check where you are, do one thing, confirm it worked, then take the next step.

That’s now written into how we work, and you can read the rest of that process in how I build with AI agents.