Get back to previous version in remote repository with git


I did a commit 2 days ago by mistake in git remote repository that make a lot of errors in live website.

How can I get back to previous version before 2 days ago but in remote repository not in my local test code only?


I do git checkout master

enter image description here


  1. git reset –hard #reset local changes
  2. git clean -fd #remove untracked files and folders
  3. git fetch #fetch latest
  4. git checkout master #switch to master
  5. git pull #get latest from master
  6. git checkout -b my-fix-branch #create new branch from master
  7. git revert {faulty-commit-hash} #remove your change
  8. git push -u origin my-fix-branch:my-fix-branch #push to remote
  9. git checkout master #switch again to master
  10. git merge my-fix-branch #merge fix to master
  11. git push #push to master


  • If you get merge conflicts on step 7 you will need to fix them.
  • If you don’t have rights to modify master directly, after step 8 create a pull request from "my-fix-branch" to "master"

Answered By – sanurah

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published