1. The 2 AM Force Push Heart Attack
Every developer has a horror story about Git. Mine happened during a group project in my third year of college.
It was late at night, and I had spent four hours fixing a nasty authentication bug. I wanted to push my branch to GitHub, but Git complained that the remote branch had conflicting commits.
I didn't want to deal with merge conflicts. I was tired. So I searched online and found a command that sounded confident: git push -f origin main.
I ran it. It succeeded.
Ten seconds later, our team chat exploded. I had overwritten three days of my teammates' work because my local branch was behind the remote repository. My stomach dropped into my shoes. I sat there in total panic, convinced I had destroyed our semester project.
The Miracle of Git Reflog
That night, my senior mentor introduced me to the single greatest safety net in version control: git reflog.
Most beginners think that when you overwrite a commit or delete a branch in Git, your code is permanently gone. But Git almost never deletes data immediately. Git records every single change of the HEAD pointer in a local diary called the reference log.
By running git reflog, we found the exact commit hash from five minutes before my disastrous force push. With one git reset --hard HEAD@{1}, every single line of overwritten code was restored in seconds.
I exhaled the biggest breath of my life.
The Rules I Live By Today
That heart attack taught me lessons I will carry for the rest of my career:
- Never force push to a shared branch. If you ever need to use
-f, use--force-with-leaseinstead, which prevents overwriting commits you haven't seen. - Commit small, commit often. A commit that changes ten files is a nightmare to review or revert. A commit that changes one logical unit of work is easy to understand and rollback.
- Write honest commit messages. Replacing "fix bug", "update", and "wip" with clear descriptions like "fix: resolve GPS radius calculation on Android 14" takes five seconds and saves hours for your future self.
Version control is not a test to pass; it is a time machine that lets you take creative risks without fear of losing your work.