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 - To avoid such issues, I recommend using git push --force-with-lease. This command adds a safety check when pushing to a remote branch to avoid unexpected commits.
Discussions

Git push force 💥
If your repo allows users to mess with master then you deserve it. More on reddit.com
🌐 r/ProgrammerHumor
81
4922
December 13, 2022
git push —force
You use git via command line, I use download as zip More on reddit.com
🌐 r/ProgrammerHumor
403
4265
January 8, 2022
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
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
🌐
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:
🌐
Git
git-scm.com › docs › git-push
Git - git-push Documentation
This method is of course entirely ... git tag base master # mark our base point git rebase -i master # rewrite some commits git push --force-with-lease=master:base master:master...
🌐
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.
🌐
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
2 weeks ago - Use --force-with-lease instead of --force. The push command has another option called --force-with-lease.
Find elsewhere
🌐
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. To do this, use command/ctrl to multi-select the desired commits from the graph, and then select Squash 3 commits.
🌐
Datree
datree.io › resources › git-push-force
Git push force [a Git commands tutorial] | Datree.io
Altering commit history and rewriting ... a simple git push will fail and we will have to bypass the “fast forward” rule. Enter --force....
🌐
Scaler
scaler.com › home › topics › git › git push force
Git Push Force- Scaler Topics
May 4, 2023 - The command used to push is: If ... This --force option will override the constraint of fast forwarding in git and will align the changes of the local branch with the changes of the remote branch on the remote server...
🌐
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 - Pro Tip: git push has many available options. --force and --all work together especially well. You can use this combo when returning to the project after several months of inactivity. Give it a try if you’re feeling extra adventurous! Refresh links, overhaul text, and change commands to be up-to-date.
🌐
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: ... This command overwrites the main branch's history with that of feature-branch.
🌐
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 ...
🌐
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.
🌐
Medium
noaabarki.medium.com › dont-underestimate-the-push-force-5cba944a246d
Don’t Underestimate the push — force | by Noaa Barki | Medium
January 24, 2020 - Altering commit history and rewriting commits that have already been pushed can be done using git rebase, git squash and git commit — amend, but be warned my friends that these mighty commands don’t just 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.
🌐
Educative
educative.io › answers › what-is-the-git-push---force--u-origin-command
What is the git push --force -u origin command?
The git push --force -u origin command overrides this restriction in Git, meaning it allows you to forcefully overwrite the commit history of your local branch to the remote repository branch.
🌐
Medium
medium.com › @vitaliystanyshevskyy › git-push-origin-master-force-eec683936622
git push origin master -- force 💥 | by Vitaliy Stanyshevskyy | Medium
May 2, 2018 - 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.
🌐
Medium
medium.com › @python-javascript-php-html-css › how-to-force-a-git-push-correctly-6be2c833ec40
How to Force a Git Push Correctly | by Denis Bélanger
August 24, 2024 - The use of git push origin temp-branch:main — force in the script forcefully updates the remote main branch with the contents of a temporary local branch. This is particularly useful when you want to overwrite the remote changes with your ...
🌐
DEV Community
dev.to › ruqaiya_beguwala › day-1230-git-push-force-with-lease-safer-alternative-to-force-5fc
Day 12/30 - git push --force-with-lease – Safer alternative to --force - DEV Community
June 2, 2025 - By default, --force-with-lease checks the entire remote branch, but you can enforce stricter checks by specifying which ref (commit) you expect to be at the tip. git push --force-with-lease=origin/main:expected-ref-here
🌐
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.
🌐
Squash
squash.io › how-to-force-a-git-push
How To Force A Git Push - Squash Labs
August 11, 2023 - 2. Once you have the latest changes, use the git push command with the --force or -f option to force push your local changes to the remote repository: