If you’ve ever felt like Git has a personal vendetta against you, you’re not alone.
Even after years of coding, Git still manages to surprise me—in all the wrong ways. I’ve pushed to the wrong branch, deleted files I needed, and once even leaked an API key (yep, that happened).
These are the five Git mistakes I’ve made most often—and how you can fix them fast when they happen to you.
1. Committing to main instead of a feature branch
You’re in the zone, commit your work, and only then realize—you were on main. Again.
# Move the commit to a new branch
git branch feature-branch
git reset HEAD~ --hard
git checkout feature-branch
This moves your commit to a new branch, resets main, and switches you over.
Lesson learned: Always run git status before committing. It’s a small habit that prevents big headaches.
2. Writing terrible commit messages
We’ve all done it:
“fix stuff,” “asdf,” or my personal favorite—“PLEASE WORK.”
A week later, you have no idea what “stuff” was.
How to fix it:
# If not pushed yet
git commit --amend -m "Add user authentication to login page"
# If already pushed (be careful)
git commit --amend -m "Add user authentication to login page"
git push --force
Pro tip: Use this simple format:
[verb] [what] [why] → Fix login bug causing session timeout
3. Deleting a file (and committing the deletion)
It’s the “oh no” moment. You realize you deleted something important after you’ve committed it.
How to fix it:
# Find the commit where it existed
git log -- path/to/deleted-file
# Restore it
git checkout <commit-hash> -- path/to/deleted-file
Git remembers everything. Even your mistakes. That’s oddly comforting.
4. Forgetting to create a branch before coding
You code for an hour, then realize you never switched branches.
Now your work is tangled up in main.
How to fix it:
git stash
git checkout -b feature-branch
git stash pop
Lesson learned: Start every session with
git checkout -b <feature-name>
Make it muscle memory.
5. Pushing sensitive data (like API keys)
The one mistake that makes your heart stop.
I once pushed an .env file to GitHub—and got a security alert within minutes.
How to fix it:
git rm --cached .env
echo ".env" >> .gitignore
git add .gitignore
git commit -m "Remove .env from version control"
git push
Then rotate those credentials immediately. Assume they’re compromised.
Lesson learned:
Use a pre-commit hook to scan for sensitive files, and double-check your .gitignore before that first push.
The Pattern I Noticed
Every time I broke Git, it wasn’t the command’s fault—it was my mental model.
Once I understood what Git was actually doing, everything started to click.
That’s exactly why I built GitPath.dev
A hands-on way to learn Git in the terminal, with clear steps and expected outcomes for every command.
No simulators. No vague tutorials. Just real, practical lessons.
What's the Git mistake that still haunts you?
Drop it in the comments — I guarantee you're not the only one who's made it.
Top comments (0)