It happens to the best of us, there are many occasions when you need to remove a commit from a remote branch, you just need to be very careful doing this. I do it the following way
Removing a Commit from a Remote Git Repository
1 min read
I first get to the target branch by running git checkout target-branch-name or if the branch is not available locally first run git fetch origin target-branch-name then checkout.
Then run git log to list all current commits, if the latest commit you see is the one you want to remove run git reset HEAD^ —soft this will remove the commit, and you will see the changes available locally.
All you need to do now is run git push origin target-branch-name —force this will force push to your branch and remove the commit you now have as local changes.
That’s my process of doing it, I find it very useful when something is working locally but not on staging/production, so I push a bunch of commits in a row, and when I finally get it right, I git reset HEAD^ —soft all the commits and push it all in just one commit