By A. Akotkar · 16 November 2026
Ask how to force push without wrecking a teammate’s work and the answer comes back in one flag: --force-with-lease. One popular guide calls it “a safer alternative to --force that prevents overwriting commits you haven’t seen”.
Git’s own documentation is less sure. The git-push manual carries “a general note on safety” under that flag, and the note says the protection is “trivially defeated” in a situation many developers are in without knowing it.
This post covers what the flag checks, how the check goes wrong, and the companion option Git added to fix it. Everything here comes from the Git manual, the Git release notes and the VS Code documentation. The commands are quoted from that documentation and were not run for this post.
TL;DR: Plain --force-with-lease compares the remote branch with your local remote-tracking ref, such as origin/feature. Any git fetch updates that ref, so after a fetch the push goes through even if a teammate’s new commit was never looked at. Editors and scheduled jobs that fetch in the background do this silently. Since Git 2.30 you can add --force-if-includes, which also requires the remote tip to appear in your local branch’s reflog. Set push.useForceIfIncludes to true to apply it every time. For the strictest check, name the exact commit you expect with --force-with-lease=<branch>:<commit>.
- What does
--force-with-leasecheck? - So where does the protection fail?
- Is anything on your machine fetching in the background?
- What does
--force-if-includesadd? - Is there a stricter option?
- What to set before your next rebase
What does --force-with-lease check?
It checks one thing: that the branch on the server still points where your local copy of it says it does.
The manual puts it this way: the flag “will protect all remote refs that are going to be updated by requiring their current value to be the same as the remote-tracking branch we have for them.” The remote-tracking branch is origin/feature, your machine’s record of where feature was on the server the last time you fetched.
So the lease is a comparison between the server and a bookmark. If a teammate has pushed since your last fetch, the two differ and the push is refused. That is the behaviour the tutorials describe, and it is real.
Plain --force has no such comparison. The manual says it “can cause the remote repository to lose commits; use it with care.”
So where does the protection fail?
It fails when the bookmark moves and you do not notice.
A git fetch updates origin/feature to match the server. It does not touch your local feature branch or your rebased commits. After the fetch, the bookmark and the server agree again, the lease check passes, and the push replaces your teammate’s commit with your history.
The manual’s wording is blunt. Using the flag without an explicit expected value “interacts very badly with anything that implicitly runs git fetch on the remote to be pushed to in the background.” It goes on: the protection “is trivially defeated if some background process is updating refs in the background.”
It also admits why: “We don’t have anything except the remote tracking info to go by as a heuristic for refs you’re expected to have seen & are willing to clobber.” Git cannot tell the difference between a commit you fetched and reviewed and one a tool fetched while you were at lunch.
Is anything on your machine fetching in the background?
Quite possibly, and it depends on your editor’s settings.
VS Code documents a setting for it. Its source control docs say: “To automatically fetch commits in the background, use the git.autofetch setting. It is off by default in the editor window and on by default in the Agents window.” The interval is set by git.autofetchPeriod, “default 180 seconds”.
The Git manual’s own example is a scheduled job running git fetch origin. Other editors and Git clients were not checked for this post, so look at the settings of whichever one you use.
A manual fetch has the same effect. The guide quoted at the top shows a workflow that starts with git fetch origin, rebases onto origin/main, then pushes with the lease. That fetch refreshes the bookmark for the feature branch as well. If a colleague pushed to the feature branch in the meantime, nothing in that sequence stops their commit being overwritten.
What does --force-if-includes add?
A second check: that the commit on the server is one your local branch has already incorporated.
The Git 2.30 release notes introduced it with a plain statement of the problem: --force-with-lease “can easily be misused to lose commits unless the user takes good care of their own “git fetch”.” The new option “attempts to ensure that what is being force-pushed was created after examining the commit at the tip of the remote ref that is about to be force-replaced.”
The manual defines it as: “Force an update only if the tip of the remote-tracking ref has been integrated locally.” Git looks through the reflog of your local branch for the remote tip. If a background fetch brought in a commit you never rebased onto or merged, it is not there, and the push is rejected.
The two options go together:
git push --force-with-lease --force-if-includes
On its own the new option does nothing. The manual says that passed without --force-with-lease “it is a “no-op”.” One widely read tutorial lists it under “Bypass Lease Checks” and shows it alone, with the flag misspelled. It is the opposite of a bypass.
To avoid typing it each time, the git-config manual documents push.useForceIfIncludes: “If set to true, it is equivalent to specifying” --force-if-includes “as an option” on the command line.
Is there a stricter option?
Yes: tell Git the exact commit you expect to replace.
The form --force-with-lease=<refname>:<expect> compares the server against a value you supply and ignores the remote-tracking ref entirely. It is the original design. The Git 1.8.5 release notes describe only this form, as “a more fine grained control over a blunt” --force.
The manual still marks the shorter forms as provisional: all forms other than the explicit one “are still experimental and their semantics may change as we gain experience with this feature.” That sentence sits in the documentation of the flag most tutorials recommend without qualification.
The manual’s worked example marks the starting point with a tag before rewriting history:
git fetch # update 'master' from remotegit tag base master # mark our base pointgit rebase -i master # rewrite some commitsgit push --force-with-lease=master:base master:master
It is more typing, which is presumably why the short form won.
What to set before your next rebase
- Run
git config --global push.useForceIfIncludes true, the setting the git-config manual documents, so every--force-with-leasepush gets the reflog check. It needs Git 2.30 or later. - Check whether your editor fetches in the background. In VS Code the setting is
git.autofetch. - In scripts and CI, use the explicit form with a commit hash. A script has no memory of what was reviewed.
- Treat a rejected lease as information. Fetch, read what arrived, rebase onto it, and push again.
- Keep force pushes to branches you own. Hosting platforms offer branch protection for shared branches; those features were not reviewed for this post.
Read next: when a rebase does go wrong and you need to find which commit broke things, git bisect turns the hunt into a binary search.
Sources checked 16 November 2026. Applies to Git 2.30 and later; the git-push manual was read as published for Git 2.56.1.






Leave a Reply