# git push --force can delete your teammate's commits. Use this instead.

> One flag and one setting stop a plain force push from wiping commits you never saw.

Source: https://fullbytedeveloper.com/blog/force-lease
Published here: 2026-11-13

A plain force push wiped a teammate's fix off the shared branch in a test repo. One flag and one setting stop it.

## The fix

```bash
git push --force-with-lease
git config --global push.useForceIfIncludes true
```

## How it works

**Step 1: Swap --force for --force-with-lease.** It refuses if the remote moved since your last fetch [1].

**Step 2: Set push.useForceIfIncludes once.** If your editor fetched in the background, the lease alone passes because Git thinks you have seen the new commit. This setting also checks that you actually integrated the remote commit [2].

**Step 3: Read the rejection.** Pull or rebase onto the new commit before you push again.

## What we ran

Git 2.54.0, bare repo plus two clones, no network:

- `--force`: `+ 4d85209...de09ed6 main -> main (forced update)`. The fix was gone from origin.
- `--force-with-lease`: `! [rejected] main -> main (stale info)`. Nothing lost.
- After a background fetch, `--force-with-lease` passed.
- With `push.useForceIfIncludes true`: `! [rejected] main -> main (remote ref updated since checkout)`. The gap closed.

## The catch

The setting only adds protection to `--force-with-lease`. It does nothing for plain `--force`. The teammate's commit was still in their own clone, so it is recoverable, but nobody else on the branch sees it until they push again.

## Optional alias

```bash
git config --global alias.pushf "push --force-with-lease"
```

Send this to the teammate who force pushes to the shared branch without a second thought.

## Sources

1. [Git docs: git-push](https://git-scm.com/docs/git-push)
2. [Git docs: push.useForceIfIncludes](https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushuseForceIfIncludes)
