3

Can somebody explain to me why git push -f is bad?

If it is bad, why does it exist?

I would really appreciate if you give a situation when we should do git push -f.

  • The second helpful answer in the duplicate link discusses the pitfalls of force pushing in Git. – Tim Biegeleisen Jul 10 '20 at 04:30
  • @TimBiegeleisen it didn't really answered my question :( –  Jul 10 '20 at 05:18
  • What remaining question(s) do you have which were not answered in the duplicate link? – Tim Biegeleisen Jul 10 '20 at 05:24
  • It only answered a situation when to do git push -f :( I wanted to know why is it bad to git push -f and if it is really bad, why did it exist? –  Jul 10 '20 at 05:31
  • [See here](https://stackoverflow.com/questions/10510462/force-git-push-to-overwrite-remote-files) for a few reasons to do a force push. – Tim Biegeleisen Jul 10 '20 at 05:48
  • There are few tools that are inherently bad (imo force push is not one of them). Just the way they are used... – fredrik Jul 10 '20 at 07:11
  • Force push is to correct mistakes. If you are alone working in your branch or in your repository, that's perfectly fine to use it. If you are working with other people, that could bring more inconvenient than advantages (learn about that). That's why teams prefer not using it. But saying is 'bad' is a little bit reductive. – Philippe Jul 10 '20 at 07:51
  • It is not bad if you use it for correcting a grave mistake (e.g. committing wrong/sensitive files) for pushing to a branch that only you use. For regular corrections just use commits. If you use force push with branches already cloned and used by other users things get more complicated. Especially if they are going to push back the commits you already changed/deleted. – Jay Jul 10 '20 at 10:36
  • Thank you @Philippe!!! I completely got it now. –  Jul 13 '20 at 05:40
  • Most of the time, before force pushing, you should discuss with other devs to warn they will encounter probable sync problems. For more explanation, I think it's call 'bad' mostly for beginners until they learned the subtleties and also for (big) opensource project where you don't know who could follow your work. And as force push is an history rewrite, it is even less "permitted" in the `master` branch than in other branches. But once again that's a case by case evaluation if it worth it.... – Philippe Jul 13 '20 at 13:15

0 Answers0