The Hook (The "Byte-Sized" Intro)
Pilots don't take off without a checklist. Surgeons don't operate without one. You shouldn't git reset without one either. It takes 10 seconds, saves hours of recovery. Five checks. That's all.
š What is the Reset Safety Checklist?
A simple pre-flight checklist to run through before executing any git reset command ā especially --hard. Each step prevents a common data-loss scenario.
Conceptual Clarity
The 5-point checklist:
| # | Check | Command | Why |
|---|---|---|---|
| 1 | Am I on the right branch? | git branch --show-current | Resetting the wrong branch is catastrophic |
| 2 | Do I have uncommitted work? | git status | --hard destroys uncommitted changes |
| 3 | Which mode do I need? | Think: soft/mixed/hard | Wrong mode = wrong outcome |
| 4 | Note the current SHA | git rev-parse HEAD | Your escape hatch if things go wrong |
| 5 | Is this pushed? | git log origin/main..main | Resetting pushed commits requires force-push |
Real-Life Analogy
This checklist is like looking both ways before crossing the street. You could skip it. You'd probably be fine. But the one time you're not fine, the consequences are severe. Ten seconds of checking saves hours of recovery.
Visual Architecture
Why It Matters
- Prevents wrong-branch resets: The most common reset mistake.
- Saves uncommitted work:
--harderases working tree changes permanently. - Ensures correct mode: Soft when you want to recommit, hard when you want to discard.
- Enables recovery: The saved SHA lets you undo the reset via
git reset --hard <sha>.
Code
# āāā The 5-point checklist in practice āāā
# 1. Confirm branch
git branch --show-current
# Output: feature/login ā Am I on the right branch?
# 2. Check for uncommitted work
git status
# If "Changes not staged" or "Untracked files" appear,
# stash or commit them first if using --hard
# 3. Choose mode
# --soft ā keep staging + working tree
# --mixed ā keep working tree only
# --hard ā discard everything
# 4. Save current position
git rev-parse HEAD
# Output: abc1234def5678... ā Copy this!
# 5. Check if pushed
git log --oneline origin/main..HEAD
# If empty ā everything is pushed ā DON'T reset (use revert)
# If shows commits ā those are local-only ā safe to reset
# āāā Now execute āāā
git reset --soft HEAD~1 # (or whatever you chose)
# āāā If something went wrong āāā
git reset --hard abc1234def5678 # Use the saved SHAQuick Copy-Paste Checklist
Pre-Reset Checklist:
ā” git branch --show-current ā Correct branch?
ā” git status ā Uncommitted work safe?
ā” Mode decided: soft/mixed/hard
ā” git rev-parse HEAD ā SHA noted for recovery
ā” git log origin/main..HEAD ā Local-only commits?Key Takeaways
- Always run through the 5 checks before any
git reset. - Save the current SHA ā it's your instant recovery path.
- Check if commits are pushed ā if yes, use
revertinstead. - The checklist takes 10 seconds and prevents hours of recovery.
Interview Prep
-
Q: What should you do before running
git reset --hard? A: Verify you're on the correct branch, check for uncommitted changes (which will be lost), note the current commit SHA for recovery, and confirm the commits haven't been pushed to a shared branch. -
Q: How do you check if your local commits have been pushed? A: Run
git log --oneline origin/<branch>..HEAD. If it shows commits, those are local-only and safe to reset. If empty, all commits are pushed and you should userevertinstead. -
Q: What is
git rev-parse HEADused for? A: It outputs the full SHA of the current HEAD commit. Noting this before a reset provides an immediate recovery path ā if the reset goes wrong, you cangit reset --hard <sha>to return to the original state.