Intermediate · 3 min read
Never use --force again
Why --force-with-lease exists and why it should be your only way to force push.
The problem with --force
--force replaces the remote branch with yours, no questions asked. If a colleague pushed in the meantime, their commits are gone from the remote.
The polite version
--force-with-lease checks that the remote is still where you last saw it. If someone pushed, it refuses. Fetch, look, then decide.
Safe
$ git push --force-with-lease
Make it the default
Create an alias so you never type the dangerous version by accident.
Safe
$ git config --global alias.pushf "push --force-with-lease"