When is it safe to force push, and how do you avoid destroying teammates' work?
Take a moment.
Say your answer out loud or write it down first — retrieval is what makes it stick. Reveal when you're ready.
Short answer
Never force-push to shared branches (main, develop) that others base work on. On your own feature branch, prefer git push --force-with-lease over plain --force — it aborts if the remote has commits you haven't fetched, preventing accidental overwrites.
Detailed explanation
git push --force overwrites the remote branch unconditionally — if a teammate pushed while you weren't looking, their commits vanish from the remote and recovery is painful. --force-with-lease adds a safety check: it only pushes if the remote ref matches your last-fetched state, so you can't clobber unseen commits. Force-pushing is acceptable only on personal branches where you're the sole contributor. If shared work does get clobbered, teammates recover by force-pushing their local copy (which still has the commits) back up.
Example
# Safe force push (aborts if remote changed):
git push --force-with-lease origin feature/login
# Teammate recovers after an accidental force-push:
git fetch origin
git push --force-with-lease origin feature/loginInterview tip
Lead with the golden rule — never force-push shared branches — then explain the lease safety net. Mentioning teammate recovery shows real-world ops awareness.
Common mistakes
- Using --force as a default instead of a deliberate last resort.
- Force-pushing main or develop without team coordination.
- Not knowing --force-with-lease exists or how it differs.