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'
Discussions

I'm struggling to understand how to roll back to a previous point. I want to disregard the crossed out chain completely. What am I missing here?
Edit: That was definitely it. I undid the new commit and created a new branch and it is acting as I was expecting now. I decided the last 3 commits I did were just not going to work, so I wanted to roll back to my v0.1.5a commit. So I "Undo Last Commit" a few times to get back there, then tried committing to a chain. I didn't actually create a branch, maybe that was what I did wrong? More on reddit.com
🌐 r/git
12
0
December 11, 2024
Can you git revert a commit without reverting recent commits?
Yes, you can revert a single commit anywhere in the history. Depending on the changes made since that commit, you may need to resolve conflicts. https://git-scm.com/docs/git-revert More on reddit.com
🌐 r/git
5
12
March 29, 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
I want to revert the code to a previous commit.
git checkout -f HEAD~16 -- . will make your code go back 16 commits in your local storage, without rewriting any history with those 16 commits. The "changes" (reverting the past 16 commits) should be at the staging area at this moment. Now you can git commit to commit those reverted code and then git push to update your Github repo. To be sure you did it right, try git diff HEAD..HEAD~17 to compare your branch to the branch 17 commits ago (the 16 commits you wanted to revert + the new commit that did the revert = 17 commits). If the command outputs nothing, you're all good. More on reddit.com
🌐 r/git
4
2
November 8, 2022
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 ...
🌐
Medium
devdiaryacademy.medium.com › git-rollback-resetting-a-branch-to-a-specific-commit-a-case-study-19daf94c2c78
Git Rollback: Resetting a Branch to a Specific Commit — A Case Study | by Developer Diary | Medium
February 10, 2026 - This can be a lifesaver when dealing with critical issues or when you need to revert to a stable state of your project. However, a word of caution is necessary. Using git reset --hard and force pushing with --force can disrupt collaboration ...
🌐
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 - Resetting a remote repository to a specific commit in Git can be an important task, especially when you need to revert changes or roll back to a stable state. This article will guide you on how To Reset Remote Repository to a Certain Commit in Git. ... This method involves resetting your local branch to the desired commit and then force-pushing the changes to the remote repository.
🌐
Graphite
graphite.com › guides › git-revert-commit-after-pushing
git revert commit after pushing
Use git revert for commits that have already been pushed to shared repositories, and git reset only for local commits that haven't been shared. Yes, you can revert a merge commit, but it requires special handling.
🌐
Sentry
sentry.io › sentry answers › git › revert a git repository to a previous commit
Revert a Git repository to a previous commit | Sentry
You can use the git revert command to return your repository’s files to a previous state without rewriting the commit history. This is done by creating new commits that do the opposite of existing commits, i.e. removing lines and files that ...
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. ... Avoid using git push --force to overwrite the remote repository’s history, as it can cause issues for ...
🌐
Better Stack
betterstack.com › community › questions › how-to-revert-multiple-commits
How Can I Revert Multiple Git Commits? | Better Stack Community
Identify the Commits to Reset: ... the first commit you want to remove). Reset the Branch: Use git reset with the -hard option to reset the branch to a specific commit, discarding commits after that commit:...
🌐
Quora
quora.com › How-do-I-revert-a-specific-git-commit
How to revert a specific git commit - Quora
Answer (1 of 2): You can either do git reset or git revert to roll back your commit changes. I suggest using git revert and then pushing your modified changes [code]# Reset the index and working tree to the desired tree # Ensure you have no uncommitted changes that you want to keep git reset ...
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-revert-a-commit-with-git-revert
How To Revert A Commit With Git Revert? - GeeksforGeeks
July 30, 2025 - Now, a new commit is added and then we can use the git push command to push the reverted changes to the branch. ... Since the git revert command adds a new commit by default. This flag applies the revert to your working directory and staging ...
🌐
Aviator
aviator.co › home › blog › how to git undo commit: methods and best practices
How to Git Undo Commit: Methods and Best Practices - Aviator Blog
February 10, 2025 - This creates a new commit that reverses the changes of a specific commit, leaving the commit history intact. Imagine you’re working on a platform for customer subscriptions and pushing a commit that accidentally removes the logic for automatic renewals. Other developers may have already pulled the changes, so you can’t use git reset. Instead, you use git revert ...
🌐
CloudBees
cloudbees.com › blog › git-revert-explained
Git Revert Explained: Safely Undoing Your Changes
November 29, 2021 - This process will revert only the commit with the bug and create a safe way to proceed. Git revert undoes changes in a project commit history without tampering with it. Git revert undoes changes in a project commit history without tampering with it. When reverting, this operation takes the specific commit, inverts the changes from that commit, and implements a new reverse commit—only removing the changes tied to the reverted commit.
🌐
Reddit
reddit.com › r/git › i'm struggling to understand how to roll back to a previous point. i want to disregard the crossed out chain completely. what am i missing here?
r/git on Reddit: I'm struggling to understand how to roll back to a previous point. I want to disregard the crossed out chain completely. What am I missing here?
December 11, 2024 - If you absolutely want to roll-back ... newer commits: git reset --hard <oldcommitID> ... This is great feedback, thank you! Very fair, I was just kinda clicking buttons in the GUI just hoping I hit the right ones.
🌐
Git
git-scm.com › cheat-sheet
Git Cheat Sheet
git checkout <commit> <file> OR git restore <file> --source <commit> git remote add <name> <url> git push origin main · git push · git push -u origin <name> git push --force-with-lease · git push --tags · git fetch origin main · git pull --rebase · git pull origin main OR git pull ·
🌐
Vercel
chroniconl.vercel.app › articles › revert-a-commit-using-git
Revert to a Specific Commit in Git - Matthew Bub
February 25, 2024 - If Git indicates any merge conflicts, resolve them by editing the conflicted files, then add and commit those changes. git add . git commit -m "Resolved merge conflicts while reverting" If you're working on a shared repository (e.g. GitHub), push the changes to the remote repository:
🌐
Conventional Commits
conventionalcommits.org › en › v1.0.0
Conventional Commits
A common workflow for this is to have your git system automatically squash commits from a pull request and present a form for the lead maintainer to enter the proper git commit message for the merge. Reverting code can be complicated: are you reverting multiple commits?
🌐
Fork
git-fork.com
Fork - a fast and friendly git client for Mac and Windows
Fork's Diff Viewer provides a clear view to spot the changes in your source code quickly. With history view you can find all commits where a particular file or directory was changed. With blame view you can find the last commit which changed a particular file line. Fetch, pull, push · Commit, amend · Create and delete branches and tags · Create and delete remote repos · Checkout branch or revision · Cherry-pick, revert ·
🌐
Medium
medium.com › @rogeriofbrito › git-reset-remote-repository-to-a-certain-commit-5cf4ced8882c
GIT: reset remote repository to a certain commit | by Rogério Ferreira Brito | Medium
August 24, 2019 - The first step is reset your local branch, using the command git reset [<mode>] [<commit>]. How we are reseting both working tree and index, we are use the mode — hard. The commit option is de commit id with is we wish back to.
🌐
Nobledesktop
blog.nobledesktop.com › learn › git › undo changes in git: git checkout, git revert, & git reset
Undo Changes in Git: checkout, revert, & reset
April 19, 2026 - NOTE: The —no-edit option prevents Git from asking you to enter in a commit message. If you don't add that option, you'll end up in the VIM text editor. To exit VIM, press : to enter command mode, then q for quit, and finally hit Return (Mac) or Enter (Windows). This will make a new commit that is the opposite of the existing commit, reverting the file(s) to their previous state as if it was never changed. If working with a remote repo, you can now push those changes: