Why is git push --force dangerous and what's the safer alternative?
⚡
Quick Answer
--force overwrites remote history and can erase teammates' commits; --force-with-lease refuses if the remote moved since you last fetched.
Detailed Answer
A plain force-push replaces the remote branch unconditionally, clobbering anything pushed in the meantime. --force-with-lease only succeeds if the remote is where you expect, protecting against overwriting others' work. Prefer it whenever you must rewrite a shared branch.
Code Example
git push --force-with-lease origin feature
💡
Interview Tip
Always suggest --force-with-lease over --force.
gitforce-pushsafety