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
3325

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.

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

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
13
June 8, 2024
Am I using git push --force the right way?
That sounds like the right approach, and the one I use. After the rebase, your local dev1 history is different than the remote's dev1 branch. That is expected after a rebase, because a rebase changes history. Though I would recommend that you use --force-with-lease instead of --force to avoid clobbering any commits that you do not have locally which might have been pushed to the dev1 branch. Just a good habit. More on reddit.com
🌐 r/git
9
7
October 4, 2018
git push --force and how to deal with it
tl;dr protected branches and --force-with-lease More on reddit.com
🌐 r/git
9
15
September 19, 2017
git push --force and how to deal with it
git push --force-with-lease More on reddit.com
🌐 r/programming
84
76
September 19, 2017
🌐
Medium
noaabarki.medium.com › dont-underestimate-the-push-force-5cba944a246d
Don’t Underestimate the push — force | by Noaa Barki | Medium
January 24, 2020 - The force flag allows us to order Git “do it anyway”. Whenever we change our history or whenever we want to push changes that are in consists with the remote branch we should use push — force.
🌐
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.

🌐
DataCamp
datacamp.com › tutorial › git-push-force
Git Push Force: How it Works and How to Use it Safely | DataCamp
July 24, 2025 - Now, picture your Git branch like a chapter in a shared book that your team is writing together. A standard push is like adding new paragraphs at the end of the chapter. However, a git push --force is more powerful and rips out the current chapter and replaces it entirely with your version.
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › git push force
How to Git Push Force | Solutions to Git Problems
August 5, 2022 - Because you have failed to pull those changes, they are not reflected in your local repository. In this case, if you perform a Git push force, you will replace the remote repository with a copy of your local repo, effectively deleting your team member’s work.
Find elsewhere
🌐
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 - You can use the --force flag (or -f for short). This can look like an easy workaround when the git push command does not work, but it is rarely recommended — it’s not the default behavior for a reason.
🌐
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 - However, as an excellent guide from a separate field famously reminds us, “DON’T PANIC”! After all, the upside is that you’re using Git, and that means everything can be fixed. Let’s start with the best case scenario: someone else working on the same code pulled a recent version of the main branch just before you broke it. In this case, all you have to do is to go into your team chat and ask this person to force push their recent changes.
🌐
Reddit
reddit.com › r/git › am i using git push --force the right way?
r/git on Reddit: Am I using git push --force the right way?
October 4, 2018 -

Hello everyone,

I would like to know if I'm using git push --force the right way. Here is my scenario:

  1. I branched off master (let's call my branch dev1) which I did some work on and then pushed up remotely

  2. A ton of work has been done on `master` I've been working on dev1 locally

  3. I want my local dev1 branch to have all the updated changes that master has so I rebased

  4. At this point, my local dev1 is way out of sync with remote dev1. Git is saying if I want to sync them up then I need to do a git pull (but I definitely don't want to pull the changes down from the remote branch to my newer, local branch).

Assuming no one else works on dev1, am I supposed to git push --force to sync local `dev1` to remote `dev1`? If not, what are my alternatives?

🌐
Reddit
reddit.com › r/git › git push --force and how to deal with it
r/git on Reddit: git push --force and how to deal with it
September 19, 2017 - Your client will say "hi, server, I'm going to force push from A to this new commit" and if the server isn't at A (if somebody else has pushed in the meantime) then your force push will be rejected. Nice and safe. ... Only if you have these commits locally. Case 2 is a case when you can't look into your reflog. ... Or just use git revert?
🌐
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
The git force push command is typically used in scenarios where you need to update the commit history on a remote repository to match your local repository, even if it means discarding changes that are on the remote but not in your local repository.
🌐
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.
🌐
Parasrah
blog.parasrah.com › posts › git-push-force
git --force | parasrah
February 23, 2022 - Meaning it will succeed only if it’s appending to the history upstream. To “force” a push is to override this behaviour, allowing you to remove or change commits that already exist upstream. The syntax of git push (which you can verify by reading man git-push) is as follows:
🌐
Medium
medium.com › @vitaliystanyshevskyy › git-push-origin-master-force-eec683936622
git push origin master -- force 💥 | by Vitaliy Stanyshevskyy | Medium
May 2, 2018 - The reflog is Git’s safety net. It records almost every change you make in your repository, regardless of whether you committed a snapshot or not. You can think of it as a chronological history of everything you’ve done in your local repo. If you take the latest master, modify the branch history and push it with--force flag, you can revert back to the original state and fix the remote master branch with git reflog command.
🌐
Reddit
reddit.com › r/programming › git push --force and how to deal with it
r/programming on Reddit: git push --force and how to deal with it
September 19, 2017 - Instead of --force option, use --force-with-lease. It will halt the push operation if someone has pushed to the same branch while you were working on it (and haven’t pulled any changes). See this article from Atlassian. ... Forgive me if this sounds like a stupid question, but what is your workflow if you find yourself using git push --force on any sort of regular basis?
🌐
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
$ git push -f ... To github.com:adamchainz/example.git + 1fd4fb8...e025fa5 camembert -> camembert (forced update)
🌐
Medium
medium.com › free-code-camp › git-please-a182f28efeb5
Git Please: how to force push without being a jerk | by Buddy Reno | We’ve moved to freeCodeCamp.org/news | Medium
January 16, 2017 - To summarize Git’s documentation, using force-with-lease tells git to check whether the remote repo is the same as the one you’re trying to push up. If it isn’t, git will throw an error instead of blindly overwriting the remote repo.
🌐
Better Stack
betterstack.com › community › questions › how-to-properly-force-git-push
How Do I Properly Force a Git Push? | Better Stack Community
To force a Git push, you typically use the -f or --force option with the git push command. This is useful when you need to overwrite remote changes that conflict with your local repository or when you need to update a branch that has diverged ...