# Rewinding a remote branch [GIT]

You were working in a feature branch but accidentally pushed commits to the master/develop branch.

First, you have to know the exact commit ID or number of commits that was pushed. You can use `git log pretty=oneline` to get the information.

If you don't have an exact copy of the branch you would love to revert to and would love to keep the commit history, then create a dummy branch that holds the exact commit logs, ensure it branches from the branch with the original changes `git checkout -b {dummy-branch-name}`

Next, return back to the branch you pushed to accidentally with `git checkout {branch-name}` and run `git reset {commit-id} --hard` if you have a valid commit ID or `git reset HEAD^{commit-count}` if you have a commit count you want to revert back to.

Next, do `git stash` to put the changes aside in a trash can, ensure that the head of the current branch is at the exact commit you want, then run `git push --force`. This would force a rewrite in the remote branch and revert the changes as you had done locally.

I hope this removes someone from distress!!!

*Gracias*
