Lessons · Git · what force does to everybody else
What force does to everybody else
A normal push only fast-forwards. --force says the branch is whatever you have, and anything on the remote that is not in your history stops being on the branch.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
--force-with-lease refuses when the remote has moved since your last fetch, which is exactly the case where forcing would drop somebody's work.
How to think about it
Fetch, look at what each side has, then decide. If you must rewrite a shared branch, --force-with-lease is the version that can tell you no.
Worked example
git log --onelineOne commit here, and it is not the one the remote has.
git push --force-with-lease origin mainRefused: stale info. The remote moved since you last looked.
git fetch -q originSo look.
git log --oneline origin/mainThere is their commit. Forcing would have removed it.
Your turn
Find out what the remote has, before deciding anything.
git -q origin
Try it in a real repository
The trap
Reaching for plain --force when the lease refuses. The refusal is the tool telling you there is work you have not seen.