Search code examples
gitgithubgit-reset

Delete commits on remote git


I have a dev branch on which we push everything. The last commit breaks our entire build and I need to remove the same. For local i used

git reset --hard <SHA_ID>

Which works well for local repo but when I try to push the changes are rejected because the tip of current branch is behind remote and shows me to use git pull before pushing it again.

My question is, how do I make the remote go to the same HEAD as my local repo and delete the last commit.


Solution

  • You can use the --force argument to "reset" a remote branch to the same commit on your local repo:

    $ git push origin --force
    

    Note that this is considered a bad practice, though, as you may cause quite a mess for people relying on this branch. A friendlier approach would be to acknowledge the mistaken commit and fix it by git reverting it, instead of trying to "act as though it never happened" with git reset.