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.

🌐
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 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
Force "git push" to overwrite remote files - Stack Overflow
But, git push origin your_branch:some_branch --force and this was what I was missing. Hope it helps! 2022-06-30T18:44:49.877Z+00:00 ... G. P. W. Rajeg · G. P. W. Rajeg Apr 19 at 7:38 · I attested that this works! I had the same issue of "Everything is up-to-date" until I saw this comment. Many thanks! 2026-04-19T07:38:16.637Z+00:00 ... I had the same issue, however currently I am getting this message (github ... More on stackoverflow.com
🌐 stackoverflow.com
I accidentally force pushed to my repo
I accidentally force pushed to my repo, and I want to go back to the previous version. What do I do? Beta Was this translation helpful? Give feedback. ... The great thing about Git though is that it does it’s very best to never lose data, so the version of the repository before step #4 is ... More on github.com
🌐 github.com
8
60
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
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-force-git-push
How to Force Git Push? - GeeksforGeeks
July 23, 2025 - Enable branch protection rules to prevent force pushes and require pull request reviews before merging. This helps maintain a stable main branch. Use GitHub Actions to automate tasks such as testing, building, and deploying your code.
🌐
DataCamp
datacamp.com › tutorial › git-push-force
Git Push Force: How it Works and How to Use it Safely | DataCamp
July 24, 2025 - This restricts direct edits and prevents accidental force pushes to important branches. If you want to learn more about managing private repos, check out our Introduction to GitHub Concepts course to understand how to review pull requests when collaborating on GitHub. git push --force offers a useful method for rewriting your repo’s history, whether you want to clean commits or remove sensitive data.
🌐
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 - If your colleague makes changes, ... you run push --force-with-lease on the CLI, you will still overwrite these commits. For this reason, we check if there are unmerged commits on the remote branch and present a warning if we find any. If you’re hosting your remote repository on GitHub, you can use ...
🌐
Datree
datree.io › resources › git-push-force
Git push force [a Git commands tutorial] | Datree.io
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.
Find elsewhere
🌐
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 - Read the GitHub docs for more details. Instead of the --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).
🌐
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 - 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.
🌐
GitHub
gist.github.com › wojtha › 1281288
Git - force push to remote · GitHub
Git - force push to remote. GitHub Gist: instantly share code, notes, and snippets.
🌐
Graphite
graphite.com › guides › git-force-push
How to Git force push - Graphite
git push -f origin feature-branch · You should then see something like: Terminal · Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done.
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › git push force
How to Git Push Force | Solutions to Git Problems
August 5, 2022 - Learn how to Git push force using GitKraken Client, how to force push in the CLI, and see why force pushing in Git can be considered dangerous and how to mitigate risks.
🌐
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 - 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)
🌐
GitHub
gist.github.com › ddeveloperr › 97e7866b3da8042f1ea6324d337a1836
How to force “git push” to overwrite remote repo files WITH LOCAL files
Download ZIP · How to force “git push” to overwrite remote repo files WITH LOCAL files · Raw · git_push_force_upstream.md · git push -f <remote> <branch> git push -f origin master ·
🌐
Medium
noaabarki.medium.com › dont-underestimate-the-push-force-5cba944a246d
Don’t Underestimate the push — force | by Noaa Barki | Medium
January 24, 2020 - if you wish to completely avoid push — force, GitHub and GitLab offer a very cool feature called Protected Branches, which allows you to mark any branch as protected so no one will be able to push — force it (you can also set admin preferences for that matter like admin permissions).
🌐
Quora
quora.com › What-happens-to-other-users-when-we-use-the-git-push-force-command
What happens to other users when we use the 'git push --force' command? - Quora
Third, if the repo on GitHub is empty (because you just created it), use git push —force, because git won’t push to an empty repo otherwise.
🌐
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.
🌐
Reddit
reddit.com › r/git › is using force push standard workflow for github?
r/git on Reddit: Is using force push standard workflow for GitHub?
April 16, 2021 -

Hello,

I have a feature branch that I had to rebase on the master branch. However, After rebasing the push to the remote feature branch failed with the following error: "Updates were rejected because the tip of your current branch is behind its remote counterpart"

sof: https://stackoverflow.com/questions/39399804/updates-were-rejected-because-the-tip-of-your-current-branch-is-behind-its-remot

Querying the internet tells me the solution is to git push -f to the remote feature branch. Isn't this anti-pattern in git to do a force push just because GitHub cannot automatically fast-forward the rebased commit?

Thoughts? thanks

Top answer
1 of 4
11
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.
2 of 4
1
This is not specific for GitHub. If you would rebase some branch that you share with others (ie any remote branch) you may undo work done by others (thats why you get the warning), sometimes this is necessary. We all use different workflow but I would not use ´push -f´ in my daily workflow, I would use it if I need to clean up something that requires a rebase of a remote branch (and then inform my co-workers). If you are the only developer you may do what you find best for you.
Top answer
1 of 6
1506

You should be able to force your local revision to the remote repo by using

git push -f <remote> <branch>

(e.g. git push -f origin master). Leaving off <remote> and <branch> will force push all local branches that have set --set-upstream.

Just be warned, if other people are sharing this repository their revision history will conflict with the new one. And if they have any local commits after the point of change they will become invalid.

Update: Thought I would add a side-note. If you are creating changes that others will review, then it's not uncommon to create a branch with those changes and rebase periodically to keep them up-to-date with the main development branch. Just let other developers know this will happen periodically so they'll know what to expect.

Update 2: Because of the increasing number of viewers I'd like to add some additional information on what to do when your upstream does experience a force push.

Say I've cloned your repo and have added a few commits like so:

            D----E  topic
           /
A----B----C         development

But later the development branch is hit with a rebase, which will cause me to receive an error like so when I run git pull:

Unpacking objects: 100% (3/3), done.
From <repo-location>
 * branch            development     -> FETCH_HEAD
Auto-merging <files>
CONFLICT (content): Merge conflict in <locations>
Automatic merge failed; fix conflicts and then commit the result.

Here I could fix the conflicts and commit, but that would leave me with a really ugly commit history:

       C----D----E----F    topic
      /              /
A----B--------------C'  development

It might look enticing to use git pull --force but be careful because that'll leave you with stranded commits:

            D----E   topic

A----B----C'         development

So probably the best option is to do a git pull --rebase. This will require me to resolve any conflicts like before, but for each step instead of committing I'll use git rebase --continue. In the end the commit history will look much better:

            D'---E'  topic
           /
A----B----C'         development

Update 3: You can also use the --force-with-lease option as a "safer" force push, as mentioned by Cupcake in his answer:

Force pushing with a "lease" allows the force push to fail if there are new commits on the remote that you didn't expect (technically, if you haven't fetched them into your remote-tracking branch yet), which is useful if you don't want to accidentally overwrite someone else's commits that you didn't even know about yet, and you just want to overwrite your own:

git push <remote> <branch> --force-with-lease

You can learn more details about how to use --force-with-lease by reading any of the following:

  • git push documentation
  • Git: How to ignore fast forward and revert origin [branch] to earlier commit?
2 of 6
167

You want to force push

What you basically want to do is to force push your local branch, in order to overwrite the remote one.

If you want a more detailed explanation of each of the following commands, then see my details section below. You basically have 4 different options for force pushing with Git:

Copygit push <remote> <branch> -f
git push origin master -f # Example

git push <remote> -f
git push origin -f # Example

git push -f

git push <remote> <branch> --force-with-lease

If you want a more detailed explanation of each command, then see my long answers section below.

Warning: force pushing will overwrite the remote branch with the state of the branch that you're pushing. Make sure that this is what you really want to do before you use it, otherwise you may overwrite commits that you actually want to keep.

Force pushing details

Specifying the remote and branch

You can completely specify specific branches and a remote. The -f flag is the short version of --force

git push <remote> <branch> --force
git push <remote> <branch> -f

Omitting the branch

When the branch is omitted, Git will figure it out based on your config settings. In Git versions after 2.0, a new repo will have default settings to push the currently checked-out branch:

git push <remote> --force

while prior to 2.0, new repos will have default settings to push multiple local branches. The settings in question are the remote.<remote>.push and push.default settings (see below).

Omitting the remote and the branch

When both the remote and the branch are omitted, the behavior of just git push --force is determined by your push.default Git config settings:

git push --force
  • As of Git 2.0, the default setting, simple, will basically just push your current branch to its upstream remote counter-part. The remote is determined by the branch's branch.<remote>.remote setting, and defaults to the origin repo otherwise.

  • Before Git version 2.0, the default setting, matching, basically just pushes all of your local branches to branches with the same name on the remote (which defaults to origin).

You can read more push.default settings by reading git help config or an online version of the git-config(1) Manual Page.

Force pushing more safely with --force-with-lease

Force pushing with a "lease" allows the force push to fail if there are new commits on the remote that you didn't expect (technically, if you haven't fetched them into your remote-tracking branch yet), which is useful if you don't want to accidentally overwrite someone else's commits that you didn't even know about yet, and you just want to overwrite your own:

git push <remote> <branch> --force-with-lease

You can learn more details about how to use --force-with-lease by reading any of the following:

  • git push documentation
  • Git: How to ignore fast forward and revert origin [branch] to earlier commit?
🌐
Scaler
scaler.com › home › topics › git › git push force
Git Push Force- Scaler Topics
May 4, 2023 - Git normally only allows you to push changes if you have previously updated your local branch with the latest commits from your remote. So, you can transfer your own latest code commits to the remote server by using the push command only if they are up to date. If you want to avoid pushing --force altogether, GitHub and GitLab provide us with a very cool feature known as Protected Branches.
Top answer
1 of 1
11

If I’m understanding correctly, you’re talking about a scenario like the following:

  1. You have a repo named ben3eee/some-repo
  2. You create a few commits on branch some-branch
  3. You push some-branch to ben3eee/some-repo on GitHub using git push
  4. You squash the commits into one using git rebase -i
  5. You  force push some-branch to ben3eee/some-repo on GitHub using git push -f
  6. You now want to restore some-branch to the way it was before step #4

The great thing about Git though is that it does it’s very best to never lose data, so the version of the repository before step #4 is still available as long as too much time hasn’t passed. The exact definition of “too much time” is kind of fuzzy and depends on how many other changes you’ve made between step #4 and step #6. For this example, I’m going to assume that you realize your mistake right away and no other actions were taken other than the ones in the list above.

The command that can help is called git reflog. You can enter git reflog and see all of the actions that have changed your local repository, including switching branches and rebases, going back quite a ways. I’ve created a simple reflog that shows the scenario I described above:

b46bfc65e (HEAD -> test-branch) HEAD@{0}: rebase -i (finish): returning to refs/heads/test-branch
b46bfc65e (HEAD -> test-branch) HEAD@{1}: rebase -i (squash): a
dd7906a87 HEAD@{2}: rebase -i (squash): # This is a combination of 2 commits.
a3030290a HEAD@{3}: rebase -i (start): checkout refs/heads/master
0c2d866ab HEAD@{4}: commit: c
6cab968c7 HEAD@{5}: commit: b
a3030290a HEAD@{6}: commit: a
c9c495792 (origin/master, origin/HEAD, master) HEAD@{7}: checkout: moving from master to test-branch
c9c495792 (origin/master, origin/HEAD, master) HEAD@{8}: pull: Fast-forward

You can see at HEAD@{7} I performed a checkout moving from master to test-branch. I then created three commits, “a”, “b” and “c”. Then I rebased them, arriving at HEAD@{0}. The notation HEAD@{number} is the position of HEAD at “number” changes ago. So HEAD@{0} is HEAD where HEAD is now and HEAD@{4} is HEAD four steps ago. We can see from the reflog above that HEAD@{4} is where we need to go in order to restore the branch to where it was before the rebase and 0c2d866ab is the commit ID (also sometimes called “SHA”) for that commit.  So in order to restore test-branch to the state we want, we can issue the command:

git reset --hard HEAD@{4}

Then we can force push again to restore the repository on GitHub to where it was before.