# Pushing after Rewriting History

If we've previously pushed the branch, the server will reject our push after rewriting history, which can be forced with `--force-with-lease`.

![](/files/-LS9hp2brCgnCQEtSUQT)

**Important**:

Before using the commandline version of force push such as `git push --force-with-lease` or `git push --force`, you should make sure the `push default` setting is not `match`. When it's `match` git will push all your local branches that matches the branches on the remote server thus extremely dangerous when combined with `force`

```
# to get the value from the global settings
# assuming it.s global as very likely you won't configure it per project
git config --global --get push.default
# to set the value to nothing
git config --global push.default nothing
```

See <https://git-scm.com/docs/git-config#git-config-pushdefault> for other options

#### What is the difference between force-with-lease and force push <a href="#what-is-the-difference-between-force-with-lease-and-force-push" id="what-is-the-difference-between-force-with-lease-and-force-push"></a>

Force with lease is a little bit safer than force as it checks if the remote branch at local PC is the same as the branch at the remote server, for example, the push of `awesome_branch` to GitHub (let's say we are using GitHub) will fail if the local `origin/awesome_branch` at our side is different to the `awesome_branch` on GitHub (Someone else may have pushed something to the branch, but we haven't fetch the commits).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gittutorial.gitbook.io/practical-git-via-gitextensions/rewrite-history/how-to-push-after-rewriting-history.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
