georoot georoot - 11 months ago 50
Git Question

Delete commits on remote git

I have a

branch on which we push everything. The last commit breaks out 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 remote come on same HEAD as my local repo and delete the last commit.

Answer Source

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.