Git: Force push safely with --force-with-lease
If someone else has pushed new commits to the remote branch, a force push will remove them without any indication!
To guard against unintentional commit removals, use the alternative option --force-with-lease. This mode requires that you have already fetched the remote branch’s latest commit.
Improve the “lease” protection with --force-if-includes. This option requires that you have also checked out the remote branch’s latest commit.
git push --force-with-lease --force-if-includes
I recommend to set this up as Git alias.
Published: 2025-05-21