Common Git Mistakes (And How to Fix Them)

Published: (January 6, 2026 at 11:12 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

1. Committing on main instead of a feature branch

Fix:

git checkout -b feature-branch
git reset --soft HEAD~1
git commit

This moves your commit onto a new branch without losing changes.

2. Working on the wrong branch

Fix:

git checkout -b new-branch

Your work stays intact.

3. Poor commit messages

Fix:

git commit -m "Fix null pointer error in user login"

Good commit messages save time during reviews and debugging.

4. Accidentally committing sensitive files (e.g., .env)

Fix:

git rm --cached .env
echo ".env" >> .gitignore
git commit -m "Remove env file from repo"

If secrets were pushed, rotate them immediately.

5. Merge conflicts with leftover conflict markers

Fix: Resolve the conflict, remove the >>>>>> markers, then:

git add .
git commit

6. Need to undo a change without rewriting shared history

Fix:

git revert 

Never rewrite shared history unless absolutely necessary.

7. Lost a commit after a reset or rebase

Fix:

git reflog

Find the commit hash and recover it:

git checkout 

Git almost never truly deletes your work.

8. Using git push --force on a shared branch

Fix:

git push --force-with-lease

This is safer and prevents overwriting others’ work.

9. Creating unnecessary merge commits

Fix:

git pull --rebase

Keeps history clean and avoids unnecessary merge commits.

10. Making multiple unrelated changes in a single commit

Guideline:

  • One feature
  • One fix
  • One idea per commit

Git mistakes happen to everyone; what matters is knowing how to recover. Once you understand how Git tracks history, it becomes a powerful safety net rather than a source of stress. Learn the tools, respect shared branches, and don’t panic—Git is usually on your side.

Back to Blog

Related posts

Read more »

Commit Message Format

Commit Message Format Each commit message consists of a header, a body, and a footer. The header has a special format that includes a type, an optional scope,...

Understanding Git in Simple way - Part 2

Hello, I'm Ganesh. I'm working on FreeDevTools online, currently building a a single platform for all development tools, cheat codes, and TL;DRs — a free, open‑...