Assuming that your branch is called master both here and remotely, and that your remote is called origin you could do:

 git reset --hard <commit-hash>
 git push -f origin master

However, you should avoid doing this if anyone else is working with your remote repository and has pulled your changes. In that case, it would be better to revert the commits that you don't want, then push as normal.

Update: you've explained below that other people have pulled the changes that you've pushed, so it's better to create a new commit that reverts all of those changes. There's a nice explanation of your options for doing this in this answer from Jakub Narębski. Which one is most convenient depends on how many commits you want to revert, and which method makes most sense to you.

Since from your question it's clear that you have already used git reset --hard to reset your master branch, you may need to start by using git reset --hard ORIG_HEAD to move your branch back to where it was before. (As always with git reset --hard, make sure that git status is clean, that you're on the right branch and that you're aware of git reflog as a tool to recover apparently lost commits.) You should also check that ORIG_HEAD points to the right commit, with git show ORIG_HEAD.

Troubleshooting:

If you get a message like "! [remote rejected] a60f7d85 -> master (pre-receive hook declined)"

then you have to allow branch history rewriting for the specific branch. In BitBucket for example it said "Rewriting branch history is not allowed". There is a checkbox named Allow rewriting branch history which you have to check.

Answer from Mark Longair on Stack Overflow
Top answer
1 of 11
1989

Assuming that your branch is called master both here and remotely, and that your remote is called origin you could do:

 git reset --hard <commit-hash>
 git push -f origin master

However, you should avoid doing this if anyone else is working with your remote repository and has pulled your changes. In that case, it would be better to revert the commits that you don't want, then push as normal.

Update: you've explained below that other people have pulled the changes that you've pushed, so it's better to create a new commit that reverts all of those changes. There's a nice explanation of your options for doing this in this answer from Jakub Narębski. Which one is most convenient depends on how many commits you want to revert, and which method makes most sense to you.

Since from your question it's clear that you have already used git reset --hard to reset your master branch, you may need to start by using git reset --hard ORIG_HEAD to move your branch back to where it was before. (As always with git reset --hard, make sure that git status is clean, that you're on the right branch and that you're aware of git reflog as a tool to recover apparently lost commits.) You should also check that ORIG_HEAD points to the right commit, with git show ORIG_HEAD.

Troubleshooting:

If you get a message like "! [remote rejected] a60f7d85 -> master (pre-receive hook declined)"

then you have to allow branch history rewriting for the specific branch. In BitBucket for example it said "Rewriting branch history is not allowed". There is a checkbox named Allow rewriting branch history which you have to check.

2 of 11
259

Most other answers – including the accepted one – will result in unnecessary loss of local state.

Local changes are not inherently required to change a remote. You may need to apply local corrections in addition to resetting a remote, but that's a lower priority if your problem is simply that you need to quickly put the remote back to how it was before your push, or you pushed the wrong thing. This method (like any other forced push) has the potential to ruin your remote if you choose the wrong commit, but even then you can usually find the correct one and try again.

You must have the desired commit somewhere in your local repo that the remote should match.

  1. Do not do any local resetting, checking out, or branch switching.

  2. Use git log to find the commit you want to the remote to be at. Use git log -p to see changes, or git log --graph --all --oneline --decorate to see a compact tree.

    If you cannot find the commit, try checking git reflog which will show the state history of your repo. You may be able to recover the commit from its hash, e.g.:

    git branch <name for branch of rescued commit> <hash of rescued commit>
    
  3. Copy the commit's hash, tag, or (if it's the tip) its branch name.

  4. Run a command like:

    git push --force <remote> <commit-ish>:<the remote branch>
    

    e.g.

    git push --force origin 606fdfaa33af1844c86f4267a136d4666e576cdc:main
    

    or

    git push --force staging v2.4.0b2:releases
    

If the forced push fails, it's likely disabled by the remote. This may be worked around by temporarily changing one or both of receive.denyNonFastForwards and receive.denyDeletes. If your remote is hosted on a service without shell access, it probably has settings you can change to allow forced pushes.


I use a convenient alias (git go, mnemonic "graph oneline") for viewing history, which can be added like so:

git config --global alias.go 'log --graph --oneline --all --decorate'
🌐
OpenReplay
blog.openreplay.com › openreplay blog › undoing local and remote changes with git revert
Undoing Local and Remote Changes with git revert
November 25, 2024 - Upload the changes to the remote repository with git push: ... git revert creates a new commit that undoes one or more commits, preserving the commit history.
Discussions

Does git revert also affect the remote branch?
If you do the revert on the same branch and then push, your change will also be on the remote branch. In general, everything you do will only affect the local repository unless you push. More on reddit.com
🌐 r/git
13
8
April 14, 2023
[Git] How to 'git reset' a remote branch?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/learnprogramming
13
5
February 12, 2024
People also ask

What happens if I encounter conflicts while reverting a commit?
Resolve the conflicts manually, stage the changes, and then run `git revert --continue` to complete the revert operation.
🌐
blog.openreplay.com
blog.openreplay.com › openreplay blog › undoing git commits after push: safely revert changes on remote repositories
Undoing Git Commits After Push: Safely Revert Changes on Remote ...
🌐
GitHub
gist.github.com › gunjanpatel › 18f9e4d1eb609597c50c2118e416e6a6
Git HowTo: revert a commit already pushed to a remote repository · GitHub
Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it. ... Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32.
🌐
GitHub
gist.github.com › vishaltelangre › 5531806
Revert last local or remote commit (git) - Gist - GitHub
Now git log will show that our last commit has been removed. ... If you have already made your commits public, you will want to create a new commit which will "revert" the changes you made in your previous commit (current HEAD).
🌐
Graphite
graphite.com › guides › git-hard-reset-remote
Git hard reset to remote - Graphite
Synchronizing a local branch with ... in the remote repository, especially if a rebase or merge is not feasible. Discarding local changes that are no longer needed or are incorrect. Reverting a branch to a clean state before applying new changes. A hard reset changes the state of your repository to a specific commit. Here’s how it works in detail: Resetting the HEAD: The HEAD in Git is a reference ...
Find elsewhere
🌐
OpenReplay
blog.openreplay.com › openreplay blog › undoing git commits after push: safely revert changes on remote repositories
Undoing Git Commits After Push: Safely Revert Changes on Remote Repositories
November 30, 2024 - Use git revert <commit-hash> to create a new commit that undoes the specified commit. ... Push the new commit to the remote repository.
🌐
Medium
medium.com › @sharath.ravi › how-to-revert-a-git-commit-from-a-remote-repository-easy-step-by-step-tutorial-358f4a72fa1d
How to revert a git commit from a remote repository? Easy step-by-step tutorial. | by Sharath Ravi | Medium
March 21, 2020 - After this, if you check your repository status(using ‘git status’), you’ll notice that you have the HEAD detached at the commit you tested before. Then, push the new commit hash to a new branch in local (I created a local branch called ‘test-revert’) and push the branch to remote using commands:
🌐
Reddit
reddit.com › r/learnprogramming › [git] how to 'git reset' a remote branch?
r/learnprogramming on Reddit: [Git] How to 'git reset' a remote branch?
February 12, 2024 -

Say I have a local branch and I make change A, then push it so both the local and remote has change A. I then realize I don't want change A as there was an error in it. I can use git reset to reset my local branch to the commit before change A, but then if I do that and try to push, it doesn't work. This makes sense because technically the local branch is behind the remote branch. And a solution to this is to just make a "revert change A" commit, but I don't even want my commit history to show these two commits since they cancel each other out

Is there a way to do "git reset" a remote branch?

🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to git reset to remote
How to Git Reset to Remote {3 Simple Methods}
February 4, 2026 - Follow the steps below to reset a local branch to a remote HEAD: 1. Switch to the branch you want to reset using git checkout.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-reset-remote-repository-to-a-certain-commit-in-git
How To Reset Remote Repository to a Certain Commit in Git? - GeeksforGeeks
June 26, 2024 - ... Step 3. Fetch Latest Changes: Fetch the latest changes from the remote repository. ... Step 4. Revert to the Desired Commit: Use the `git revert` command to create new commits that undo the changes.
🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
Experiment locally before you push to the remote repository. # Modify history from commit-id to HEAD (current commit) git rebase -i commit-id · When contributing to large open source repositories, consider squashing your commits into a single commit. This practice: Helps maintain a clean and linear project history. Simplifies the process of reverting changes, as all changes are condensed into one commit.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-reset-a-git-branch-to-a-remote-repository
How to Reset a Git Branch to a Remote Repository? - GeeksforGeeks
May 22, 2024 - Resetting a Git branch to a remote repository is a straightforward process that involves fetching the latest changes, resetting your branch to match the remote branch, and optionally force pushing the changes. This process can help you synchronize your local branch with the remote repository, ensuring consistency and avoiding potential conflicts.
🌐
Medium
medium.com › @bsalwiczek › 4-ways-to-remove-changes-from-remote-branch-in-git-8634fc7b397a
4 Ways to Remove Changes From Remote Branch in GIT | by Bartosz Salwiczek | Medium
April 13, 2022 - If you’ve been working with git ... to a remote branch that shouldn’t be there. Sometimes it’s just a silly local file, but it may happen that you push a sensitive data, like credentials there (for example you forgot to add a configuration file to .gitignore). In this article, I will show you 4 methods to “undo” it and keep your git history clean. The first method is suitable for most cases. Git has a handy revert command that ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-undo-changes-in-git-e1da7930afdb
How to undo changes in Git
December 7, 2018 - If you have a commit that has been pushed into the remote branch, you need to revert it. Reverting means undoing the changes by creating a new commit. If you added a line, this revert commit will remove the line.
🌐
Continuously Merging
articles.mergify.com › git-reset-to-remote-head
Git Reset to Remote HEAD A Practical Guide
August 27, 2025 - git revert, on the other hand, creates a brand new commit that reverses the changes from a previous one. It doesn't alter existing history, which makes it the safe, standard way to undo changes that are already live on a remote branch.
Top answer
1 of 15
450

If nobody has pulled your remote repo yet, you can change your branch HEAD and force push it to said remote repo:

git reset --hard HEAD^ 
git push -f 

(or, if you have direct access to the remote repo, you can change its HEAD reference even though it is a bare repo)


Warning: git reset --hard discards local changes

As dremodaris correctly warns in the comments:

WARNING: the --hard option will also make you lose your changes in your local working directory!


Note, as commented by alien-technology in the comments below, on Windows (CMD session), you would need ^^:

git reset --hard HEAD^^
git push -f 

And, as noted in the comments by Jon Schneider:

If the command with "HEAD^" results in error no matches found: HEAD^, see "git show HEAD^ doesn't seem to be working. Is this normal?"

Update since 2011:
Using git push --force-with-lease (that I present here, introduced in 2013 with Git 1.8.5) is safer.

See Schwern's answer for illustration.


What if somebody has already pulled the repo? What would I do then?

Then I would suggest something that doesn't rewrite the history:

  • git revert locally your last commit (creating a new commit that reverses what the previous commit did)
  • push the 'revert' generated by git revert.
2 of 15
82

Set the local branch one revision back (HEAD^ means one revision back):

git reset --hard HEAD^

Push the changes to origin:

git push --force

You will have to force pushing because otherwise git would recognize that you're behind origin by one commit and nothing will change.

Doing it with --force tells git to overwrite HEAD in the remote repo without respecting any advances there.

🌐
Ruegg
christoph.ruegg.name › blog › git-howto-revert-a-commit-already-pushed-to-a-remote-reposit
Git HowTo: revert a commit already pushed to a remote repository | Christoph Rüegg
May 5, 2010 - Simply remove or fix the bad file in a new commit and push it to the remote repository. This is the most natural way to fix an error, always safe and totally non-destructive, and how you should do it 99% of the time. The bad commit remains there and accessible, but this is usually not a big ...
🌐
Opensource.com
opensource.com › article › 18 › 6 › git-reset-revert-rebase-commands
How to reset, revert, and return to previous states in Git | Opensource.com
$ git log --oneline 11b7712 Revert "File with three lines" b764644 File with three lines 7c709f0 File with two lines 9ef9173 File with one line · Here are the current contents of the file in the working directory: ... Why would you choose to do a revert over a reset operation? If you have already pushed your chain of commits to the remote repository (where others may have pulled your code and started working with it), a revert is a nicer way to cancel out changes for them.
🌐
Adamdurrant
adamdurrant.co.uk › blog › undo-git-commit
How to Undo Pushed Git Commits Locally & Remotely<!-- --> | ADurrant
First you must be sure that the changes you have made and conflicts you have resolved are correct as the next command will overwrite your remote history. ... Without --force-with-lease, Git would reject the push because it sees your history as being behind the tip of your remote repo.