Git – Reset or revert a commit pushed to remote

Sometimes after you push some commits to the remote, you realize that there is a mistake. So you need to revert all of the commits that already pushed. To do so, run these commands:

git checkout master
git reset --hard e3f1e37
git push --force origin master

Where e3f1e37 is the commit you what to reset to.

Running first 2 commands will reset your code to the commit e3f1e37 in --hard mode. That means Git will remove all your local changes.

The final command runs a forced push, telling the remote to update the branch to the same as your local branch.

Newsletter

Subscribe to our newsletter to receive news and tutorials about WordPress and web development.

Meta Box - Creating expert WordPress custom fields and custom meta boxes in minutes! Check it out →