Interview Prep/Git & GitHub/Undoing Mistakes

Your local `main` is a mess after experiments. You want it to exactly match the remote.

BeginnerScenarioUndoing Mistakes
Answer

Situation read → You accept losing all local-only commits and changes on this branch.

What I'd do →

  1. Keep a safety net: git branch backup-main.
  2. git fetch origin.
  3. git reset --hard origin/main.
  4. Remove stray files: git clean -fd (after -n).

Why → Fetch updates the remote-tracking ref without touching your branch. Reset then moves your branch and tree to it.

Interview tip → git pull would try to merge your mess; reset is the clean tool here.

All Git & GitHub questions Roadmap: Git & GitHub

More on Undoing Mistakes