Skip to content

/flags/git/git-push-force-with-lease

git push --force-with-lease: a safer force push

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
tool
Git
command
git push
flag
--force-with-lease
default
off
since
Git 1.8.5

git push --force-with-lease force-pushes only if the remote branch still points to the commit your remote-tracking branch (origin/main) recorded at your last fetch. If someone pushed in the meantime, the push is rejected with stale info instead of silently deleting their work, which is what --force would do.

Rejected when the remote moved

bash
git init -q --bare remote.git
git clone -q remote.git me 2>/dev/null && cd me
git switch -q -c main && echo v1 > f && git add f && git commit -qm v1 && git push -q origin main
cd .. && git clone -q -b main remote.git colleague && cd colleague
echo theirs >> f && git commit -qam "colleague's work" && git push -q origin main
cd ../me
git commit -q --amend -m "v1 (amended)"
git push --force-with-lease origin main

Output · exit 1

To /tmp/work/remote.git
 ! [rejected]        main -> main (stale info)
error: failed to push some refs to '/tmp/work/remote.git'

Accepted after you fetch and integrate

bash
git init -q --bare remote.git
git clone -q remote.git me 2>/dev/null && cd me
git switch -q -c main && echo v1 > f && git add f && git commit -qm v1 && git push -q origin main
git commit -q --amend -m "v1 (amended)"
git push -q --force-with-lease origin main && git log --oneline origin/main

Output

26e9abf v1 (amended)

Here nobody else pushed, so the lease holds and the rewritten commit replaces the old one.

Pitfall: background fetches

Editors and tools that run git fetch automatically update origin/main, so the lease can pass even though you never looked at the new commits. Add --force-if-includes (Git 2.30+), which also checks that the remote tip is in your local reflog:

bash
git push --force-with-lease --force-if-includes origin main

Sources