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
Git Clone
Git Remote
Git Push
Git Fetch and Pull
Exercises & Assignments
Clone a repository, make a change and push it
Get new changes from the remote with fetch and pull
Interview Questions & Answers
What is Git Clone and How to Clone a Git repository?
How can you push changes to a remote branch in Git?
What is the difference between git fetch and git pull?
What is the difference between git clone and fork?
What is origin in Git?
What is a pull request?
What is the difference between force push and force with lease in Git?