Interview Prep/Real-World Interview/Data loss and corruption

Someone ran `git push --force` to `main` and a day of other people's commits disappeared from the remote.

BeginnerTroubleshootingData loss and corruption
Answer

Likely causes → A force push replaced the remote branch with a local branch that didn't contain the newer commits. Branch protection wasn't on.

Diagnose → Find the commit main pointed at before the push: GitHub's activity view or the push event in the audit log, or any teammate's local clone (git reflog show origin/main), or the CI logs of the last build.

Fix →

git fetch origin
git push --force-with-lease origin <lost-sha>:main

Coordinate in the team channel so nobody pushes in the meantime, and ask people to rebase onto the restored main.

Prevent → Protect main: block force pushes and deletions, require PRs and status checks. Use --force-with-lease instead of --force on personal branches.

All Real-World Interview questions Roadmap: Interview readiness

More on Data loss and corruption