How to Remove GIT Commits Locally and Remotely

Remove the Commits Locally

If you only want to remove the last commit,

git reset --hard HEAD^

If you want to remove more than one, for example, 2 commits,

git reset --hard HEAD~2

Remove the Commits Remotely

Force pushing to Github by using the following command, where branchName should be replaced by the branch on which the commit resides.

git push origin +branchName --force