What is the difference between force push and force with lease in Git?

Both replace the remote branch with your local branch. The difference is the safety check.

–force–force-with-lease
Overwrites the remote branch in any caseOverwrites only if the remote branch is what you last fetched
Can delete commits pushed by your teammatesFails if someone else pushed new commits meanwhile
RiskyMuch safer

Use force push only on your own feature branches after you rewrote the history (rebase or amend), and prefer --force-with-lease. Never force push to main. See Git Push.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.