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.

🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › git push force
How to Git Push Force | Solutions to Git Problems
August 5, 2022 - This means you need to make sure your local repository is entirely up-to-date with the latest changes from the remote before running Git push force or you risk losing commits. For example, let’s say a team member pushed new changes to a remote ...
Discussions

Can't force push a ref to a remote if local repo doesn't have the commit referred to by the current remote ref
Describe the bug This is a corner case, but one I've run into frequently over the last few days. When trying to force push, if the local repository doesn't contain the commit that the remot... More on github.com
🌐 github.com
2
May 20, 2020
Git force commit and push , when getting "nothing to commit" - Stack Overflow
On branch develop Your branch is up-to-date with 'origin/develop'. nothing to commit, working tree clean · it cancel the commit ... how i force the commit and push ? so it will update the file in the remote ... To add an empty commit... git commit --allow-empty -m "testing". More on stackoverflow.com
🌐 stackoverflow.com
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
Any reason not to just push after a commit? Rather... is it worth having a command that commits and pushes right after?
Depends on if you're working with other people or not. If you are, then pushing right away means other people have access to the new commits. Then what happens if you need to undo a commit? Or you broke something and need to add another commit to fix it? Although that's what separate branches are for. But if its just you, then pushing right away isn't a big deal. Then you have a second copy just in case something happens to your local one (I've totally never accidentally deleted my local copy before). And you can always force push to fix the remote if needed. More on reddit.com
🌐 r/git
72
3
March 15, 2024
🌐
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 - Ask people not to mess with the repo for the next minute or so while you’re fixing things. 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.
🌐
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 - 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. In the scenario above, if you force push your work, you will erase Joe’s commit from the remote repo.
🌐
Git
git-scm.com › docs › git-push
Git - git-push Documentation
This flag disables that check, the other safety checks in PUSH RULES below, and the checks in --force-with-lease. It can cause the remote repository to lose commits; use it with care. Note that --force applies to all the refs that are pushed, hence using it with push.default set to matching or with multiple push destinations configured with remote.<name>.push may overwrite refs other than the current branch (including local refs that are strictly behind their remote counterpart).
🌐
Graphite
graphite.com › guides › git-force-push
How to Git force push - Graphite
Force Push not working: If the force push doesn't seem to work, ensure you have the necessary permissions to the remote repository and that the remote branch hasn't been protected against force pushes.
Find elsewhere
🌐
DataCamp
datacamp.com › tutorial › git-push-force
Git Push Force: How it Works and How to Use it Safely | DataCamp
July 24, 2025 - ... You probably have experienced this as a developer: You just realized your code had an issue in your last commit. To undo this mistake, you run some commands and rewrite your local history. When you run git push --force to clean everything up, your teammates notify you that some commits ...
🌐
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 - Use --force-with-lease instead of --force. The push command has another option called --force-with-lease. This helps to make sure that you are at least not overwriting work from others: it will present an error message and refuse to push if ...
🌐
GitHub
github.com › git-lfs › git-lfs › issues › 4140
Can't force push a ref to a remote if local repo doesn't have the commit referred to by the current remote ref · Issue #4140 · git-lfs/git-lfs
May 20, 2020 - Can't force push a ref to a remote if local repo doesn't have the commit referred to by the current remote ref#4140
Published   May 20, 2020
Author   karlhendrikse
🌐
Datree
datree.io › resources › git-push-force
Git push force [a Git commands tutorial] | Datree.io
January 23, 2020 - In the output of the git push --force command in your terminal look for the line that resembles this one: The first group of symbols(which look like a commit SHA prefix) is the key to fixing this.
🌐
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.
🌐
Medium
noaabarki.medium.com › dont-underestimate-the-push-force-5cba944a246d
Don’t Underestimate the push — force | by Noaa Barki | Medium
January 24, 2020 - Unfortunately, not being updated to the remote branch Bob accidentally erased all the records of Lilly’s changes 😰. ... One of the common mistakes using this command is when Bob forgets to update (git pull) his local tracked branch, in this case, using the force might cause Bob a lot of trouble. you must wonder why? Well… force pushes the changes with no regard to the state of the tracked branch, therefore commits might get lost in the process.
🌐
Sal Ferrarello
salferrarello.com › home › never use git push force
Never use git push force - Sal Ferrarello
January 29, 2021 - The proper way to resolve this situation, is to pull the new changes (zyx911) into our local copy. For more information on how to do this, see my Git failed to push some refs post.
🌐
Educative
educative.io › answers › what-is-the-git-push---force--u-origin-command
What is the git push --force -u origin command?
Since the git push --force -u origin command forcefully overwrites the commit history of the remote repository, its use is discouraged when working on shared repositories. If someone else makes a new commit to the remote repository that is not ...
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-force-git-push
How to Force Git Push? - GeeksforGeeks
July 23, 2025 - Step 3. Add Changes: Stage your changes using git add . or git add <file-name>. ... 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:
🌐
JetBrains
jetbrains.com › help › idea › commit-and-push-changes.html
Commit and push changes to Git repository | IntelliJ IDEA Documentation
4 days ago - The git push --force command disables ... you choose to force push, IntelliJ IDEA performs the git push --force-with-lease operation which is a safer option that helps you ensure you do not overwrite someone else's commits (refer to git push ...
🌐
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 git push --force-with-lease.
🌐
Medium
medium.com › @vitaliystanyshevskyy › git-push-origin-master-force-eec683936622
git push origin master -- force 💥 | by Vitaliy Stanyshevskyy | Medium
May 2, 2018 - But unfortunately it was not an option for me, since I haven’t had latest master. I haven’t pulled master for few days. I just typed master instead of feature branch name in my push command. ... Relatively easy — requires only few steps. ... After some time researching the web I found out the workaround. The main idea is that Git stores commits even when you delete or modify the branch.
🌐
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) A force push bypasses the fast-forward protection and always updates the remote branch, no questions asked. That allows you to proceed, although it carries the risk of potentially losing work.