Just do:

git push origin <your_branch_name> --force

or if you have a specific repo:

git push https://git.... --force

This will delete your previous commit(s) and push your current one.

It may not be proper, but if anyone stumbles upon this page, thought they might want a simple solution...

Short flag

Also note that -f is short for --force, so

git push origin <your_branch_name> -f

will also work.

Answer from Katie on Stack Overflow
Top answer
1 of 12
3320

Just do:

git push origin <your_branch_name> --force

or if you have a specific repo:

git push https://git.... --force

This will delete your previous commit(s) and push your current one.

It may not be proper, but if anyone stumbles upon this page, thought they might want a simple solution...

Short flag

Also note that -f is short for --force, so

git push origin <your_branch_name> -f

will also work.

2 of 12
327

And if push --force doesn't work you can do push --delete. Look at 2nd line on this instance:

git reset --hard HEAD~3  # reset current branch to 3 commits ago
git push origin master --delete  # do a very very bad bad thing
git push origin master  # regular push

But beware...

Never ever go back on a public git history!

In other words:

  • Don't ever force push on a public repository.
  • Don't do this or anything that can break someone's pull.
  • Don't ever reset or rewrite history in a repo someone might have already pulled.

Of course there are exceptionally rare exceptions even to this rule, but in most cases it's not needed to do it and it will generate problems to everyone else.

Do a revert instead.

And always be careful with what you push to a public repo. Reverting:

git revert -n HEAD~3..HEAD  # prepare a new commit reverting last 3 commits
git commit -m "sorry - revert last 3 commits because I was not careful"
git push origin master  # regular push

In effect, both origin HEADs (from the revert and from the evil reset) will contain the same files.


edit to add updated info and more arguments around push --force

Consider pushing force with lease instead of push, but still prefer revert

Another problem push --force may bring is when someone push anything before you do, but after you've already fetched. If you push force your rebased version now you will replace work from others.

git push --force-with-lease introduced in the git 1.8.5 (thanks to @VonC comment on the question) tries to address this specific issue. Basically, it will bring an error and not push if the remote was modified since your latest fetch.

This is good if you're really sure a push --force is needed, but still want to prevent more problems. I'd go as far to say it should be the default push --force behaviour. But it's still far from being an excuse to force a push. People who fetched before your rebase will still have lots of troubles, which could be easily avoided if you had reverted instead.

And since we're talking about git --push instances...

Why would anyone want to force push?

@linquize brought a good push force example on the comments: sensitive data. You've wrongly leaked data that shouldn't be pushed. If you're fast enough, you can "fix"* it by forcing a push on top.

* The data will still be on the remote unless you also do a garbage collect, or clean it somehow. There is also the obvious potential for it to be spread by others who'd fetched it already, but you get the idea.

🌐
DataCamp
datacamp.com › tutorial › git-push-force
Git Push Force: How it Works and How to Use it Safely | DataCamp
July 24, 2025 - When you do this, your local branch will be different from the remote branch. Then as you try to push a new commit, Git shows the error, which protects the remote branch from loss of work. Using git push --force tells Git to skip the safety check and overwrite the remote branch with what is in your local branch.
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › git push force
How to Git Push Force | Solutions to Git Problems
August 5, 2022 - When force pushing with GitKraken Client, a banner will appear with the following options: Pull (fast forward if possible), Force Push or Cancel. Note: Pull (fast forward if possible) fetches any updates on the remote branch and attempts to fast-forward, or move, the local branch to point to the same commit as the remote. If a fast-forward is not possible, a Git merge will be performed. Cancel will cancel the push. In the below example, there are a few commits that have been pushed that should be squashed.
🌐
Atlassian
atlassian.com › git › tutorials › syncing › git-push
Git Push | Atlassian Git Tutorial
A commit is often amended to update the commit message or add new changes. Once a commit is amended a git push will fail because Git will see the amended commit and the remote commit as diverged content. The --force option must be used to push an amended commit.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-force-git-push
How to Force Git Push? - GeeksforGeeks
July 23, 2025 - Step 4. Commit Changes: Commit the changes using git commit -m "Your commit message". ... Step 5. Force Push: Use the --force option to force push:
🌐
Graphite
graphite.com › guides › git-force-push
How to Git force push - Graphite
Following the instructions, run git pull to integrate the most recent remote changes then try your force push again. To force push changes from one branch to another (e.g., from feature-branch to main), you'd check out to the branch you want to push into and then force push the other branch's commits:
🌐
Git
git-scm.com › docs › git-push
Git - git-push Documentation
I.e. create a base tag for versions ... force push changes to master if the remote version is still at base, regardless of what your local remotes/origin/master has been updated to in the background. Alternatively, specifying --force-if-includes as an ancillary option along with --force-wi...
Find elsewhere
🌐
Git Tower
git-tower.com › learn › git faq › how to force push in git
How to force push in Git | Learn Version Control with Git
1 month ago - As described above, Git will normally only allow you to push your changes if you have previously updated your local branch with the latest commits from its remote counterpart. Only when you are up-to-date will you be able to push your own new commits to the remote. The --force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with your own local history.
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git push force explained [with examples]
git push force Explained [With Examples] | GoLinuxCloud
September 14, 2021 - Since the first commit we have made is wrong, we would like to overwrite user B commit 5ced2eb so that we maintain the right initial commit before any other is added. To achieve that we shall run git push --force command.
🌐
Datree
datree.io › resources › git-push-force
Git push force [a Git commands tutorial] | Datree.io
January 23, 2020 - Altering commit history and rewriting ... alter the commits — they replace all the commits, creating new ones entirely. Therefore a simple git push will fail and we will have to bypass the “fast forward” rule. Enter --force....
🌐
Git Tower
git-tower.com › blog › force push in git - everything you need to know
Force Push in Git - Everything You Need to Know | Tower Blog
August 18, 2021 - In the output of git push --force, find a line similar to this: + last-good-commit...f00f00ba main -> main (forced update) In this example, "last-good-commit" is your last good commit before everything went wrong.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-force-commit-in-git
How to Force Commit in Git? - GeeksforGeeks
June 4, 2024 - Force committing in Git involves ... commands associated with force commits are git commit --amend, git push --force, and git push --force-with-lease....
🌐
Evil Martians
evilmartians.com › blog › git push --force and how to deal with it—martian chronicles, evil martians’ team blog
git push --force and how to deal with it—Martian Chronicles, Evil Martians’ team blog
July 30, 2024 - Inside your shell, look at the output of git push --force and try to locate a line that resembles this one: + deadbeef...f00f00ba main -> main (forced update) The first group of symbols (which looks like a commit’s SHA prefix) is the key to pulling off this rescue operation.
🌐
Scaler
scaler.com › home › topics › git › git push force
Git Push Force- Scaler Topics
May 4, 2023 - Here are some of the common examples of when the need for git push force comes: After mistakenly pushing the sensitive information on the remote server. After squashing some of the commits that have been pushed to the remote.
🌐
Squash
squash.io › how-to-force-a-git-push
How To Force A Git Push - Squash Labs
August 11, 2023 - There are several scenarios where ... For example, if you accidentally committed sensitive information, like API keys or passwords, you can amend the commit and force push to remove the sensitive data....
🌐
rokpoto
rokpoto.com › home › blog › git tricks: git commit –amend + git force –push
Git Tricks: git commit --amend + git force --push | rokpoto
May 24, 2023 - Use git commit --amend + git force --push in order to keep git history stable. Learn by following a working demo.
🌐
Adam Johnson
adamj.eu › tech › 2023 › 10 › 31 › git-force-push-safely
Git: Force push safely with --force-with-lease and --force-if-includes - Adam Johnson
October 31, 2023 - But sometimes, it’s not, such as when you have amended a commit, rebased your branch, or removed commits. In those cases, use the Jedi-esque force push, enabled with -f (--force): $ git push -f ... To github.com:adamchainz/example.git + 1fd4fb8...e025fa5 camembert -> camembert (forced update)
🌐
Medium
noaabarki.medium.com › dont-underestimate-the-push-force-5cba944a246d
Don’t Underestimate the push — force | by Noaa Barki | Medium
January 24, 2020 - Your only option is to fight fire ... one: ... Imagine working on a feature branch, you pulled some changes, created a few commits and completed your part of the feature and pushed your changes up to the main repository....
🌐
GitHub
github.com › marketplace › actions › git-commit-and-push-w-force-push
Git Commit and Push w/ Force Push - GitHub Marketplace
name: publish on: push: branches: - master jobs: build: runs-on: ubuntu-latest steps: - name: checkout uses: actions/checkout@master with: ref: master - name: build uses: github-actions-x/hugo@master - name: push uses: dciborow/commit@0.0.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} push-branch: 'master' commit-message: 'publish' force-add: 'true' force-push: 'true' files: a.txt b.txt c.txt dirA/ dirB/ dirC/a.txt name: commiter name email: my.github@email.com
🌐
Centron
centron.de › startseite › git push tutorial: commands, examples, and safe force push options
Git Push Tutorial: Commands, Examples, Safe Force Push Options
September 3, 2025 - bare-server user@your-server:/path/to/your-project.git (fetch) bare-server user@your-server:/path/to/your-project.git (push) Push the local master branch to the bare repository: ... Use a force push when your local branch history has diverged ...