Lesson Completion
Back to course

Reset Safety Checklist

Beginner
7 minutesā˜…4.7Git

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:

#CheckCommandWhy
1Am I on the right branch?git branch --show-currentResetting the wrong branch is catastrophic
2Do I have uncommitted work?git status--hard destroys uncommitted changes
3Which mode do I need?Think: soft/mixed/hardWrong mode = wrong outcome
4Note the current SHAgit rev-parse HEADYour escape hatch if things go wrong
5Is this pushed?git log origin/main..mainResetting 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

flowchart TD START["šŸ”„ About to reset"] --> B["1ļøāƒ£ Right branch?"] B --> S["2ļøāƒ£ Uncommitted work?"] S --> M["3ļøāƒ£ Which mode?"] M --> H["4ļøāƒ£ Note current SHA"] H --> P["5ļøāƒ£ Pushed?"] P --> GO["āœ… Safe to reset"] style START fill:#1a1a2e,stroke:#e94560,color:#e94560 style GO fill:#1b2d1b,stroke:#53d8fb,color:#53d8fb

Why It Matters

  • Prevents wrong-branch resets: The most common reset mistake.
  • Saves uncommitted work: --hard erases 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

bash
# ─── 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 SHA

Quick Copy-Paste Checklist

text
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 revert instead.
  • 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 use revert instead.

  • Q: What is git rev-parse HEAD used 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 can git reset --hard <sha> to return to the original state.

Topics Covered

Git HistoryGit Best Practices

Tags

#git#reset#safety#checklist

Last Updated

2026-02-13