
5 Git Commands That Saved Me From Losing Work (Nobody Talks About These)
I've lost work to bad Git commands exactly 3 times in my career. Each time, I discovered a Git feature that would have saved me. Here are the 5 commands I wish someone had shown me on day one. 1. git reflog — Your Undo Button for Everything Deleted a branch? Force-pushed the wrong thing? git reflog shows EVERY action Git recorded — even ones that don't appear in git log . # See everything you've done git reflog # Output: # abc1234 HEAD@{0}: commit: broke everything # def5678 HEAD@{1}: commit: working perfectly ← go back here # ghi9012 HEAD@{2}: checkout: moving from main to feature # Restore to the working state git reset --hard HEAD@ { 1 } The story: I once ran git reset --hard on the wrong branch. 3 days of work — gone. Then a senior dev showed me git reflog . Everything was still there. Git never truly deletes anything (for ~90 days). When to use it: After any destructive operation (reset, rebase, force push, branch delete). 2. git stash --include-untracked — Save EVERYTHING Plain g
Continue reading on Dev.to Tutorial
Opens in a new tab

