---
title: "Need to force push after a rebase? Use --force-with-lease"
description: "git push --force-with-lease overwrites the remote branch only if it is still at the value you expect, so you do not wipe a teammate's commits. Add --force-if-includes when something fetches in the background."
url: https://ihsanalapsi.dev/articles/git-push-force-with-lease
lang: en
date: 2026-11-29
updated: 2026-11-29
tags: ["Developer tools", "Web development"]
author: Ihsan Alapsi (إحسان العبسي)
---
# Need to force push after a rebase? Use --force-with-lease

You rebased your branch, Git refused the push, so you typed `--force`. At that moment, if a teammate pushed a commit to the same branch an hour ago, their work is gone and nobody noticed. By the end of this article you will know how to force push only when the remote branch is still as you saw it, and how to close the gap that tools running fetch in the background open.

## Why does Git refuse the push after a rebase?

Git refuses the push because the remote branch is no longer an ancestor of your local branch after the rebase.

According to [the git push documentation](https://git-scm.com/docs/git-push), git push usually refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it.

`--force` drops that refusal completely: it writes your branch over the remote one whatever it holds. Here is the mistake: you assume the remote only has your old work, but you do not know whether someone added to it after you last looked.

## What does --force-with-lease do?

`--force-with-lease` overwrites the remote branch only if its current value is the value you expect, and the push fails otherwise. In other words you tell Git: "overwrite it, but only if it is still how I left it".

```bash
git push --force-with-lease
```

In this form, with no details, it protects every remote ref that is going to be updated, by requiring its current value to be the same as the remote-tracking branch you have for it. A remote-tracking branch is your local copy of the last state you saw of the remote branch, like `origin/feature`.

## How do you name the expected value yourself?

You name it with the form `--force-with-lease=<refname>:<expect>`, giving the branch name and the commit it must be on:

```bash
git push --force-with-lease=feature:3f2a9c1 origin feature
```

This form protects the named ref alone, and compares it with the value you wrote instead of the remote-tracking branch. The same documentation says all the other forms are still experimental and their meaning may change; this is the only stable one.


| Form                                  | Compares the remote branch with                      |
| ------------------------------------- | ---------------------------------------------------- |
| `--force-with-lease`                  | The remote-tracking branch of each ref being updated |
| `--force-with-lease=feature`          | The remote-tracking branch of `feature` only         |
| `--force-with-lease=feature:<expect>` | The `<expect>` value you wrote                       |


## Why does a background fetch defeat the check?

Because the form without an expected value compares with the remote-tracking branch, and any background fetch updates it without you seeing what was added. The documentation warns that `--force-with-lease` without an expected value interacts very badly with anything that runs `git fetch` in the background, like a cronjob.

Here is how it happens: your editor fetched on its own, so `origin/feature` now holds your teammate's commit, and you never looked at it. When you push, the remote value matches the one you have, so the command overwrites their work exactly like `--force`.

## How does --force-if-includes close the gap?

`--force-if-includes` allows the forced push only if the tip of the remote-tracking branch has been integrated into your local work. According to the documentation, it checks whether that commit is reachable from the reflog of your local branch, and rejects the push if not.

```bash
git push --force-with-lease --force-if-includes
```

The option does nothing on its own without `--force-with-lease`, or with the form that names an expected value, because there you already named the value. If you want to know what the reflog is and how it brings back commits, see the article on [git reflog](/articles/git-reflog-recover-commits).

## When do you need a forced push at all?

You need it when you rewrite the history of your own branch after pushing it.

That means a rebase onto main, or tidying commits with [fixup and autosquash](/articles/git-commit-fixup-autosquash). On a shared branch like main, it is safer never to rewrite history, and to fix things with [git revert](/articles/git-revert-pushed-commit).

## Where do you start today?

The next time you are about to type `--force`, type `--force-with-lease --force-if-includes` instead, and if it refuses, fetch and look at what was added before you go on. Do you share a branch with someone else?

## FAQ

**Can I make --force-with-lease my default instead of --force?**

Yes. You can set up a Git alias for it and stop typing --force at all. What matters is that you use the option every time you overwrite a branch.

**What happens if the push is refused?**

It means the remote branch changed since you last saw it. Fetch, look at what was added, and bring it into your work before you try again.

**Should I use it on main?**

Better not. Overwriting a shared branch changes history for everyone, so keep it for your own branches, and use revert on main.
