Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to perform hard push

Tags:

git

git-push

I pushed a commit to the remote repository and I want to undo that commit.

To undo the commit in my local repository I used
git reset --hard prev_commit_hash
(By the way, is this the proper way to do that?)

Then I tried to push, and failed, because the tip of my current branch is behind its remote counterpart, as I expected.

The question is: What is the proper way to perform a hard/forced push?

Edit:
I viewed some of the other similar questions asked, but they were a little old. The suggested solution was using git revert. And I saw that recently users commented that this solution is not working for them.

like image 261
Hike Nalbandyan Avatar asked Dec 24 '22 01:12

Hike Nalbandyan


1 Answers

Try using:

git push origin master -f

where f stands for forced.

like image 193
Glen Pinheiro Avatar answered Mar 07 '23 14:03

Glen Pinheiro