Git Cheat Sheet · Synchronize

Force a push

git push --force

After a rebase, an amend or a squash, your local branch no longer has the same history as its remote version: a normal push is refused. git push --force replaces the remote branch with yours. Prefer --force-with-lease, which refuses if someone has pushed in the meantime.

What it does

Replaces the remote branch with your local version, even if their histories have diverged.

A use case

You rewrote the commits of your already published working branch (amend, rebase, squash).

Warning: Remote commits missing from your local version are lost: keep this for your own branches.

On the command line

git push --force-with-lease
Forces the push only if the remote branch is the one you fetched.
git push --force
Forces without checking: overwrites any remote commit missing from your version.
git push --force-with-lease origin <branch>
Targets a specific branch.

In Merathon

  1. Small arrow next to "Push" ("Push options") → "Force push…", then confirm.

Frequently asked questions

Why prefer --force-with-lease?

If a colleague has pushed to the branch since your last fetch, --force-with-lease refuses instead of erasing their commits.

Can I force a push to main?

Avoid it: the whole team would have to realign their history. Many forges protect main to prevent it. On a shared branch, use git revert.

See also