/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
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 mainOutput · 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
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/mainOutput
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:
git push --force-with-lease --force-if-includes origin mainSources
Related pages
errors · giterror: failed to push some refs (rejected, fetch first)git push is rejected with failed to push some refs when the remote branch has commits you do not have. Pull or fetch and rebase first, then push again safely.commands · gitgit reset --soft HEAD~1: undo the last commit, keep the changesUndo the last commit and keep its changes staged with git reset --soft HEAD~1. --mixed unstages them, --hard deletes them. Undo a reset with the reflog.compare · gitgit merge vs git rebase: differences and when to use eachgit merge joins histories with a merge commit and keeps them as they happened; git rebase replays commits on a new base for a linear history with new hashes.