DEV Community

z z
z z

Posted on

10 Git Mistakes That Waste Hours — And How to Fix Them in Seconds

Here are 10 Git mistakes I've made (or cleaned up for teammates) that cost real time — and the exact commands to fix them.

1. Committed to the wrong branch

You're on main, made changes, committed. Then you realize: this should have been a feature branch.

# Create the branch you meant to use, point it at your commit
git branch feature/new-api
# Reset main back to where it was
git reset --hard origin/main
# Switch to the new branch
git checkout feature/new-api
Enter fullscreen mode Exit fullscreen mode

git branch <name> creates a branch at your current commit without switching. Then git reset --hard moves your current branch back.

2. "I need the last commit's changes but not the commit itself"

You made a commit but want to undo the commit while keeping the changes in your working directory:

git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode

--soft moves the branch pointer back one commit but leaves all changes staged. You can re-commit them differently, split them, or discard.

3. Accidentally committed a massive file

You added a 200MB video file, committed it, and now git push hangs forever.

# Remove the file from ALL commits (rewrites history)
git filter-branch --index-filter 'git rm --cached --ignore-unmatch path/to/bigfile.mp4' HEAD
# Force push
git push origin --force
Enter fullscreen mode Exit fullscreen mode

Better yet, catch it before commit with a pre-commit hook that blocks files over a threshold.

4. "I need that commit I made before I reset"

You ran git reset --hard and now the commit is gone. Not really — Git keeps it for 30 days:

# Find your "lost" commit
git reflog
# You'll see something like: HEAD@{2}: commit: Added user authentication
# Restore it
git cherry-pick HEAD@{2}
# Or checkout the whole state
git checkout HEAD@{2}
Enter fullscreen mode Exit fullscreen mode

The reflog is your safety net. It records every HEAD movement for 30 days.

5. Committed with the wrong author name

Your commit shows "Unknown" or your work email instead of your GitHub email:

# Fix the last commit's author
git commit --amend --author="Your Name <email@example.com>" --no-edit

# Fix multiple commits
git rebase -i HEAD~5
# Mark commits as "edit", then for each one run:
git commit --amend --author="... " --no-edit && git rebase --continue
Enter fullscreen mode Exit fullscreen mode

Fix your global config to prevent this: git config --global user.name "..." and git config --global user.email "...".

6. Merge conflict nightmare

A merge created conflicts in 15 files and you're not sure which changes to keep:

# Abort the merge entirely
git merge --abort

# Or use a visual diff tool
git mergetool

# Or accept all "theirs" or "ours" for specific files
git checkout --theirs path/to/file.js   # Accept incoming changes
git checkout --ours path/to/file.js     # Accept your changes
Enter fullscreen mode Exit fullscreen mode

When in doubt, abort and re-approach with a cleaner strategy.

7. "I need to undo a pushed commit"

You pushed a bad commit and need to undo it without rewriting public history:

# Create a new commit that reverses the bad one
git revert HEAD
# Push the revert
git push origin main
Enter fullscreen mode Exit fullscreen mode

git revert is safe for shared branches because it doesn't rewrite history. Use git reset only for commits that haven't been pushed.

8. "I deleted a branch I still need"

# Find the deleted branch's last commit hash
git reflog
# Look for "Branch: deleted feature/login" or the last commit message
# Restore the branch at that commit
git branch feature/login <commit-hash>
Enter fullscreen mode Exit fullscreen mode

If you haven't garbage-collected, the commits are still there.

9. "I committed on main instead of a branch" (the panic version)

You made several commits on main before realizing:

# Create branch at current position
git branch feature/new-api
# Reset main to origin (safe because we have a branch pointing to our work)
git reset --hard origin/main
Enter fullscreen mode Exit fullscreen mode

The branch you created preserves all your commits. Main is clean.

10. "The commit message is terrible"

git commit --amend -m "Actually descriptive commit message"
Enter fullscreen mode Exit fullscreen mode

Only works for the most recent commit. For older commits, use git rebase -i and mark them as "reword".


The One Command That Saves All of This

I got tired of remembering these commands, so I wrote a Claude Code skill called Git Rescue that handles all 10 scenarios automatically. You invoke it with /git-rescue and it walks you through the recovery step by step.

The full pack includes this plus 49 other skills for code review, debugging, security, and refactoring.

50 Claude Code Skills Pack — $9.99


Git's safety net (reflog, the 30-day commit retention) is incredibly forgiving once you know it. What Git mistakes have you made? Drop them in the comments.

Top comments (0)