If you have pushed the commits upstream...

Select the commit you would like to roll back to and reverse the changes by clicking Reverse File, Reverse Hunk or Reverse Selected Lines. Do this for all the commits after the commit you would like to roll back to also.

If you have not pushed the commits upstream...

Right click on the commit and click on Reset current branch to this commit.

Answer from 0xcaff on Stack Overflow
🌐
Atlassian Support
support.atlassian.com › sourcetree › kb › reset-branch-to-a-commit
Reset Branch to a Commit | Sourcetree | Atlassian Support
April 15, 2025 - This article should help users to reset a branch to a specific commit. ... 2. Then, right click on a specific commit, and select "Reset current branch to this commit".
🌐
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 - Before diving into the case study, let’s briefly understand the Git reset command. Git reset allows you to move the branch pointer to a specific commit, effectively resetting the branch’s state to that commit.
Discussions

git - How to rollback everything to previous commit - Stack Overflow
Select the commit you would like to roll back to and reverse the changes by clicking Reverse File, Reverse Hunk or Reverse Selected Lines. Do this for all the commits after the commit you would like to roll back to also. Right click on the commit and click on Reset current branch to this commit. More on stackoverflow.com
🌐 stackoverflow.com
Reset current branch to this commit in context menu
I'm going to avoid using the template as this is more of feature request than a bug report, also my apologies if this is a duplicate, I couldn't find anything after searching a few keywords. Curren... More on github.com
🌐 github.com
9
October 25, 2017
git - Resetting remote to a certain commit - Stack Overflow
You should also check that ORIG_HEAD points to the right commit, with git show ORIG_HEAD. ... 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. ... Sign up to request clarification or add additional context in comments. ... Danger danger: this reset assumes that the corresponding (tracking) branch is currently ... More on stackoverflow.com
🌐 stackoverflow.com
How do I reset a git branch to a given previous commit and fix the detached HEAD? - Unix & Linux Stack Exchange
HEAD is where your workspace is currently in the tree of git commits; detached means that it doesn't correspond to a branch. To fix this, you should create a new branch with git checkout -b branch (replacing branch with the name you want to give your new branch). If you want to drop the commits following the one you reset ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
🌐
Git
git-scm.com › docs › git-reset
Git - git-reset Documentation
Keep changes in working tree while ... branch that has nothing to do with what you committed previously. You can start a new branch and reset it while keeping the changes in your working tree....
🌐
Medium
medium.com › @vishalbarvaliya › resetting-your-git-branch-to-a-previous-commit-a-complete-guide-96cc314a172e
Resetting Your Git Branch to a Previous Commit: A Complete Guide | by Vishal Barvaliya | Medium
September 8, 2024 - You’re dealing with a merge conflict and need to revert to a clean state. The `git reset --hard` command is the most direct and forceful way to reset your branch. It performs three main actions.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 115000713344--Reset-Current-Branch-to-Here-on-local-untracked-branch-commit-history-lost
"Reset Current Branch to Here" on local untracked branch -- commit history lost? – IDEs Support (IntelliJ Platform) | JetBrains
While there is no way of restoring commits via UI, you could go to the command line, execute git reflog and find the has of the commit which was the head before you reset the branch. then checkout the comit by hash - git checkout %hash% - and ...
🌐
GitHub
github.com › desktop › desktop › issues › 3152
Reset current branch to this commit in context menu · Issue #3152 · desktop/desktop
October 25, 2017 - Currently I constantly find myself opening Git Bash to run git reset as I can't do it through the UI, I think this feature is pretty useful for inexperienced people such as myself who constantly commit mistakes and don't want to ruin their repo's ...
Author   desktop
Find elsewhere
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'
🌐
Git Scripts
gitscripts.com › git-reset-current-branch-to-commit
Git Reset Current Branch to Commit: A Quick Guide
May 1, 2026 - Execute the Reset Command Apply the reset using the command corresponding to your choice. For example: ... Be mindful this action will affect your working directory based on the chosen reset type.
Top answer
1 of 2
7

HEAD is where your workspace is currently in the tree of git commits; detached means that it doesn't correspond to a branch. To fix this, you should create a new branch with git checkout -b branch (replacing branch with the name you want to give your new branch).

If you want to drop the commits following the one you reset to, you can delete the master branch and re-create it:

git branch -D master
git checkout -b master

If you're working on a repository which is pushed elsewhere you'll need to do more work to fix things up, possibly forcing a push (and telling every one else to re-clone their workspace). If you have shared state, you should really create a revert commit; take a look at git revert (starting from master and reverting all the commits starting with the one following c70e611).

2 of 2
3

HEAD detached at c70e611

This is because when you did the git reset --hard, you were not on any branch at that time. You had a detached HEAD, and that detached head got moved with the git reset --hard command, along with a rewrite of your working tree to that state.

If you want some branch foo to be c70611, then:

git checkout foo
git reset --hard c70611

If this is considered to be a good state to push to foo's upstream then just git push <remote-name> foo.

There is a more direct way to force foo to c70611 without checking it out to be the current branch. Namely, you can rewrite what foo points to using the git update-ref command.

Before doing any of the above, I would pause and try to see how I had ended up in a detached state without noticing. Perhaps it was an unfinished rebase or whatever. Step one is to review the last few entries in the git reflog to help jog your memory.

🌐
Christian Engvall
christianengvall.se › git-reset-origin-master-to-commit
Git reset origin to commit | Christian Engvall
April 11, 2018 - Make sure you are on the branch where the commit is. I’m doing this on master. Then use git reset –hard <commit-hash> to set the current branch HEAD to the commit you want.
🌐
freeCodeCamp
freecodecamp.org › news › git-reset-hard-how-to-reset-to-head-in-git
Git Reset Hard – How to Reset to Head in Git
April 10, 2023 - In the two screenshots above, the HEAD is the commit hash d8cd0ee, with the commit message Linked JavaScript file. It is the previous commit I made. To reset the codebase to that commit, I would run git reset --hard HEAD:
🌐
JetBrains
jetbrains.com › help › idea › undo-changes.html
Undo changes in Git repository | IntelliJ IDEA Documentation
May 5, 2026 - Select the commit that you want to move HEAD onto and select Reset Current Branch to Here from the context menu.
🌐
RunCloud
runcloud.io › blog › git-reset-to-revert-previous-commit
How to Use Git Reset To Revert To Previous Commit
November 6, 2025 - git add . git commit -m "Reverted ... with this step, as it can overwrite the remote history: ... Replace <branch-name> with the name of your current branch (e.g., main or master)....
🌐
Codidact
software.codidact.com › posts › 289927
How to revert main branch to an earlier commit in git? - Software Development
Maybe you meant to add something about... (3 comments) ... Checkout the branch. Open the log window (Git Show log). Right-click on the commit/branch that you want to reset to, and choose Reset...:
🌐
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 4. Reset to the Desired Commit: Use the `git reset --hard` command followed by the commit hash you want to reset to. ... Step 5. Force Push to Remote: Force push the changes to the remote repository.
Top answer
1 of 16
10340

Setting your branch to exactly match the remote branch can be done in two steps:

git fetch origin
git reset --hard origin/master

If you want to save your current branch's state before doing this (just in case), you can do:

git commit -a -m "Saving my work, just in case"
git branch my-saved-work

Now your work is saved on the branch "my-saved-work" in case you decide you want it back (or want to look at it later or diff it against your updated branch).

Note: the first example assumes that the remote repo's name is origin and that the branch named master in the remote repo matches the currently checked-out branch in your local repo, since that is in line with the example given in the question. If you are trying to reset to the default branch in a more recent repository, it is likely that it will be main.

BTW, this situation that you're in looks an awful lot like a common case where a push has been done into the currently checked out branch of a non-bare repository. Did you recently push into your local repo? If not, then no worries -- something else must have caused these files to unexpectedly end up modified. Otherwise, you should be aware that it's not recommended to push into a non-bare repository (and not into the currently checked-out branch, in particular).

2 of 16
748

First, use git reset to reset to the previously fetched HEAD of the corresponding upstream branch:

git reset --hard @{u}

The advantage of specifying @{u} or its verbose form @{upstream} is that the name of the remote repo and branch don't have to be explicitly specified. On Windows or with PowerShell, specify "@{u}" (with double quotes).

Next, as needed, use git clean to remove untracked files, optionally also with -x:

git clean -df

Finally, as needed, get the latest changes:

git pull
🌐
Graphite
graphite.com › guides › git-hard-reset-remote
Git hard reset to remote - Graphite
Here’s how it works in detail: Resetting the HEAD: The HEAD in Git is a reference to the current commit you're working on. When you perform a git reset --hard, you move the HEAD to point to a different commit. This ...
🌐
Nestify
nestify.io › blog › using-git-reset-to-revert-to-previous-commit
Using 'git reset' to revert to previous commit - Nestify
This will keep the history the same, and it will not change the record of the branch’s history. You can do that using the steps these suggested steps: git reset –hard f414f31 git reset –soft HEAD@{1} git commit -m “Reverting to the state ...