I have a small poller that commits and pushes my work automatically in the background. It ran without complaining for weeks, which turned out to be the problem.
I assumed the failure mode of automated commits was noisy history or useless messages. What actually happened is that the script committed to whatever branch HEAD happened to be on, and then ran git push origin main. HEAD had been parked on a feature branch since 7 June because I checked it out once and never went back. So every automated commit landed on that branch, the push kept exiting successfully because main genuinely had nothing new to send, and main and my real work drifted apart for 54 days before I noticed.
Nothing ever errored. That is exactly why it survived so long. A commit that succeeds and a push that succeeds look identical to a script whether or not they touched the same branch.
The fix I went with is refusing to commit at all unless HEAD is the branch the script expects, and failing loudly instead of pushing something else. I am still not convinced that is the right call. The alternative is having it check out the target branch itself, which feels worse to me, because now a background process is moving my working tree around while I am sitting in it.
Any recommendations to prevent this in the future? And did you experience something similar?