Git Rebase –force-with-lease vs –force

Why --force-with-lease is safer

Short answer

  • --force overwrites the remote branch no matter what
  • --force-with-lease only overwrites it if no one else has pushed since your last fetch

That single check prevents accidentally deleting someone else’s work.


What git push --force actually does

When you run:

git push --force

Git tells the remote:

“I don’t care what’s on the server. Replace it with my branch.”

Result

  • Any commits pushed by teammates can be silently erased
  • Git does no safety checks
  • Works even if your local branch is outdated

This is why --force is dangerous on shared branches.


What git push --force-with-lease does differently

When you run:

git push --force-with-lease

Git says:

“Force-push only if the remote branch still points to the commit I think it does.”

In other words:

  • Git remembers the last remote commit you fetched
  • It checks the remote has not moved
  • If it has moved, the push is rejected

Concrete example (step-by-step)

1) You fetch and rebase

git fetch origin
git rebase origin/main

At this point, Git knows:

origin/main = abc123

2) A teammate pushes new commits

Remote now becomes:

origin/main = def456

3) You try to push

With --force

git push --force

✅ Push succeeds
❌ Teammate’s def456 commit is erased

With --force-with-lease

git push --force-with-lease

❌ Push is rejected:

! [rejected] main -> main (stale info)

Git protects the branch.


Why this matters in real teams

--force-with-lease prevents:

  • Overwriting teammate commits
  • Breaking CI unexpectedly
  • Forcing others to fix history messes
  • “Who deleted my commit?” moments 😅

It gives you:

  • All the power of force-push
  • With a safety lock

When --force-with-lease is still allowed

It’s safe when:

  • You rebased your own feature branch
  • You’re the only one working on it
  • The branch is not protected

Typical usage:

git push --force-with-lease origin feature/my-branch

Mental model

  • --force“Overwrite everything. I know better.”
  • --force-with-lease“Overwrite only if nothing changed since I last checked.”

Final recommendation

✅ Use --force-with-lease
❌ Avoid --force unless you fully understand the consequences

Most experienced teams ban --force outright and allow --force-with-lease instead.