--force-with-lease
A safer force push that only overwrites the remote branch if it still points where your remote-tracking branch says it does.
It still rewrites the shared branch, only with a check that you are not overwriting unseen work.
In more detail
If someone pushed after your last fetch, the lease no longer matches and the push is refused, so you do not destroy work you have not seen. Fetching right before pushing defeats that protection, because your record then matches again.
Example
git push --force-with-lease origin mainRelated terms
- force push — A push that makes the remote branch match yours even when that throws away commits the remote has.
- remote-tracking branch — A local, read-only record of where a branch on a remote pointed the last time you talked to it, such as origin/main.
Taught in
- Rebase: The Same Work, A Different History — Advanced Git Internals & Distributed Workflows
- Amend, And The One Hard Rule — Advanced Git Internals & Distributed Workflows