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 ... 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....
Discussions

How can I "force commit" the changes I'm making? I don't want to merge...

I am 100% sure that's what I want to keep!

That's very rarely true, especially for newbies.

And your caps problem is likely due to using Windows or Mac OS X, which default to case-insensitive filesystems.

More on reddit.com
🌐 r/git
16
1
May 10, 2016
Does Git create a new commit if I force push after a rebase?
A force push will update the remote to match your local tree. It won't create new commits per se, it's more that it will take your local commits and put them on the remote, wiping out anything that's different. More on reddit.com
🌐 r/git
5
5
November 8, 2018
Is force pushing really bad practice?
What you do is pretty common. Force pushing rewrites history; this is an issue if you care about that history. On a short-lived branch that exists only for a PR, no one cares about history. On main or any long-lived branch shared by multiple people, history is very important, and force pushing should never be used. More on reddit.com
🌐 r/git
27
11
June 8, 2024
Is using force push standard workflow for GitHub?
This isn't a github problem but rather is a side effect of what "rebasing" is doing. Rebasing effectively replays your commits on top of the new "base" of your branch. However while those replayed commits contain the same changes as they did before the rebase, they aren't actually the same commits. So you can' t do a standard push because you aren' t pushing new commits on top of your branch - you're effectively replacing your old branch with the new commits. And to do that you have to force push. If you don't want to force push you can merge the master branch into your feature branch instead of rebasing. You'll need to reset your branch to its previous state, merge the master branch into your feature branch, and push as normal. That will do the same effective thing as the rebase (integrate updates in master into your branch) but will do that in a merge commit instead of re-doing your commits. $ git checkout feature-branch $ git reset --hard origin/feature-branch $ git pull origin master $ git push IMO the rebase and force push workflow is a perfectly fine if You're working on a feature branch You're the only person working on the branch You haven't put up a PR for review If all of those conditions are met, rebasing and force pushing is a very nice way of keeping a clear branch history. However if anyone else is using your branch or looking at your code, force pushing is quite jarring and should be avoided at all costs. You can check out the Git documentation on rebase and the Atlassian tutorial on merging vs rebasing for more context. More on reddit.com
🌐 r/git
17
8
April 16, 2021
🌐
Git
git-scm.com › docs › git-push
Git - git-push Documentation
I.e. create a base tag for versions of the upstream code that you’ve seen and are willing to overwrite, then rewrite history, and finally 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-with-lease[=<refname>] (i.e., without saying what exact commit the ref on the remote side must be pointing at, or which refs on the remote side are being protected) at the time of "push" will verify if updates from the remote-tracking refs that may have been implicitly updated in the background are integrated locally before allowing a forced update.
🌐
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 - 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.
🌐
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:
Find elsewhere
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › git push force
How to Git Push Force | Solutions to Git Problems
August 5, 2022 - Git push force overwrites the remote repository to match exactly what your local repo looked like when you ran the command. This means you need to make sure your local repository is entirely up-to-date with the latest changes from the remote ...
🌐
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 - The command will always succeed, however, if you resort to the --force flag. You will overwrite the remote’s commit history with your local one, regardless of how different it looks. As you can see, this is a powerful command — but, as a famous web-slinger once taught us, "with great power comes great responsibility". ... There are some situations where running git push --force actually makes sense, but on most occasions, you should stay away from typing it.
🌐
Datree
datree.io › resources › git-push-force
Git push force [a Git commands tutorial] | Datree.io
January 23, 2020 - Your only option is to fight fire with fire and push --force this commit back to the branch on top of the bad one: ... Imagine working on a feature branch, you pulled some changes, created a few commits and completed your part of the feature ...
🌐
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 - So all you need is to… force push (we’re fighting fire with fire!) this commit back to the main branch, on top of the bad one. ... And congratulations! You’ve saved the day. Just be sure to learn from your mistakes! So, next, let’s say that just before you performed git push --force, someone had closed a bunch of pull requests, and so main now looks nothing like your local copy.
🌐
Atlassian
atlassian.com › git › tutorials › syncing › git-push
Git Push | Atlassian Git Tutorial
Git prevents you from overwriting the central repository’s history by refusing push requests when they result in a non-fast-forward merge. So, if the remote history has diverged from your history, you need to pull the remote branch and merge it into your local one, then try pushing again. This is similar to how SVN makes you synchronize with the central repository via svn update before committing a changeset. The --force flag overrides this behavior and makes the remote repository’s branch match your local one, deleting any upstream changes that may have occurred since you last pulled.
🌐
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 making changes to the commit history in a way that overwrites previous commits or bypasses standard merge conflicts. The primary commands associated with force commits are git commit --amend, git push --force, and ...
🌐
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 with fire and push — force this commit back to the branch on top of the bad 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. Then you squashed the commits into one, using git rebase — i and pushed again using push — force.
🌐
Squash
squash.io › how-to-force-a-git-push
How To Force A Git Push - Squash Labs
August 11, 2023 - By force pushing, you overwrite the remote branch with the amended commit that no longer contains the sensitive file. There are several scenarios where you might want to force push in Git:
🌐
Reddit
reddit.com › r/git › how can i "force commit" the changes i'm making? i don't want to merge...
r/git on Reddit: How can I "force commit" the changes I'm making? I don't want to merge...
May 10, 2016 -

Hello! I have a repository in GitHub, and I'm the only one working on it. I use it to be able to work at my home and office computers.

For some reason (stuff like this happens when I forget to send my work to GitHub sometimes), I cannot commit right now. I get the "hint: Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again." Error. But I don't want to merge anything:

All I want is for Git to totally ignore what is in the remote repository, and replace it with what I have at the moment in my computer, because I am 100% sure that's what I want to keep!

Can you please help me do this? Any help appreciated!

Edit: As is obvious, I am pretty ignorant in Git. My workflow for working on two computers is:

  • Begin session with git pull

  • Work on the files (I don't even do 'branches')

  • when finished, I run the shell script

    echo "Insert git commit comments"

    read COMM

    git add -A

    git commit -m "$COMM"

    git push

  • it works fine, and no, Dropbox is no good for me (I have reasons). :)

🌐
LabEx
labex.io › tutorials › git-when-and-how-to-use-force-pushing-in-git-411644
When and How to Use Force Pushing in Git | LabEx
However, with force pushing, you are essentially telling Git to ignore any conflicts and overwrite the remote repository with your local changes. There are a few scenarios where force pushing can be useful: Rewriting Local History: If you have made a series of commits in your local repository and want to clean up the commit history (e.g., squashing commits, rewriting commit messages, or removing sensitive information), you can use force pushing to update the remote repository with the new, cleaned-up history.
🌐
Reddit
reddit.com › r/git › does git create a new commit if i force push after a rebase?
r/git on Reddit: Does Git create a new commit if I force push after a rebase?
November 8, 2018 -

I was expecting to see a new commit when I force pushed after a rebase and looking into squashing it, but I only saw the original commit. Is this an expected behavior?

🌐
Reddit
reddit.com › r/git › is force pushing really bad practice?
r/git on Reddit: Is force pushing really bad practice?
June 8, 2024 -

When I work on a large project, I'll usually create a new branch on my fork for each thing that I implement and maybe reuse branches between PRs. On my branches, I force push a lot. Pretty much after every rebase and in a lot of situations, I don't really have any other choice or at least I don't know how to do what I want to do without force pushing. But since the branches are only used by me, I don't think it matters, right?

I keep hearing about how you are not supposed to force push.

🌐
Scaler
scaler.com › home › topics › git › git push force
Git Push Force- Scaler Topics
May 4, 2023 - The git push command is used to push all the committed code changes from a local repository to a remote server, along with ensuring that the history of git changes on the remote server is not overwritten by any chance. But, there might arise the situation when it is required to overwrite the code changes of the remote history. This is where the concept of git push force ...
🌐
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