Please can someone help me explain the difference between git push and git push -f? I do not know which of them is recommended to push your files on github
git push -f
is short for git push --force
. It forces a push when otherwise git would reject your git push
because you changed your repo history in your pushing repository. (EDIT: But that is only half the story. Forced pushes also let you overwrite someone else's commits which have been pushed after your last pull.) Use case:
git push
will not work. You can now remove commit B from your remote repo and push B' instead with git push --force
.This is ok, if only you are using that remote repo (Or no one else did a pull between B and B'). So, no, not a good idea on github.
Hope that helps.
(EDIT: You can also check the GIT documentation or the GitHub help)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With