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
🌐
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). :)

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.

Discussions

"force" git commit on local to external via push? - Stack Overflow
Possible Duplicate: Github first push problem… how to merge remote changes? My external repo is fairly outdated. I want to push all my local changes up stream. However, when I attempt to... More on stackoverflow.com
🌐 stackoverflow.com
Arguments for and against pre-commit hooks?
I'm not a fan of pre-commit hooks, as they slow me down and discourage me from making frequent, small commits. They also don't prevent code from being merged, as you can always skip them locally. Instead, I prefer integrating the tooling (like linting) directly with the IDE which gives me feedback right when typing, not when I want to commit, combined with PR checks which then actually prevent these problems from being merged in. More on reddit.com
🌐 r/git
18
7
September 16, 2023
How to change the branch without committing so that I can see the difference after I switch back ?

Git Stash - https://git-scm.com/docs/git-stash

This would allow you to stash your working dirty directory and then change to another branch.

More on reddit.com
🌐 r/git
2
4
November 30, 2020
I want to temporarily go back to a certain commit.
One among multiple approaches: git checkout X (go back in time) git checkout . (throw away changes) git checkout master (go forward to “now”) More on reddit.com
🌐 r/git
10
12
May 22, 2020
🌐
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 ... The primary commands associated with force commits are git commit --amend, git push --force, and git push --force-with-lease....
🌐
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 - When it’s not allowed (most likely because the remote repo looked different from yours, apart from your new commits), the command fails. The command will always succeed, however, if you resort to the --force flag.
🌐
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.
🌐
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 - 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.
Find elsewhere
🌐
Datree
datree.io › resources › git-push-force
Git push force [a Git commands tutorial] | Datree.io
January 23, 2020 - Altering commit history and rewriting ... a simple git push will fail and we will have to bypass the “fast forward” rule. Enter --force....
🌐
Git
git-scm.com › docs › git-commit
Git - git-commit Documentation
Before making a commit out of staged contents so far, stage the contents of paths given on the command line as well. This is usually not what you want unless you are concluding a conflicted merge. ... Make a commit by taking the updated working tree contents of the paths specified on the command line, disregarding any contents that have been staged for other paths.
🌐
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 › learn › git faq › how to force push in git
How to force push in Git | Learn Version Control with Git
1 month ago - However, consider using a tool that does NOT rewrite commit history, like git revert for example. This provides a much less obtrusive way to undo a mistake. Use --force-with-lease instead of --force. The push command has another option called --force-with-lease.
🌐
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.
🌐
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 run git push --force to clean everything up, your teammates notify you that some commits are missing or your pipeline has broken builds. In this article, I will walk you through what git push --force actually does, when to use it, and how to avoid errors.
🌐
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.
🌐
Git Scripts
gitscripts.com › git-commit-force
Mastering Git Commit Force: A Quick Guide
October 6, 2024 - Force committing is not a term that officially exists in Git commands, but it often refers to using `--force` during a push operation. The standard command `git push` updates changes on a remote repository but may reject your push if the remote ...
🌐
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 - It’s better to make the change in a completely new commit which replaces the latest unstable commit. For that we’ll use below commands: $ echo "bb" >> a # the fix to the previous commit $ git commit -a --amend --no-edit $ git push --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.
🌐
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...
🌐
JetBrains
jetbrains.com › help › rider › Commit_and_push_changes.html
Commit and push changes to Git repository | JetBrains Rider Documentation
2 weeks ago - Select Current Branch if you want ... you want to perform from the drop-down menu: Push or Force push (equivalent to git push --force-with-lease)....
🌐
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 - If you must overwrite remote history after a rebase, squash, or amended commit, use one of the force-push commands below. Force push the local branch to overwrite remote history: ... You learned how to push local commits to GitHub and to bare repositories using git push—including staging ...