Git Pushing Force Pushing


Sometimes, when you have local changes incompatible with remote changes (ie, when you cannot fast-forward the remote branch, or the remote branch is not a direct ancestor of your local branch), the only way to push your changes is a force push.

git push -f


git push --force

Important notes

This will overwrite any remote changes and your remote will match your local.

Attention: Using this command may cause the remote repository to lose commits. Moreover, it is strongly advised against doing a force push if you are sharing this remote repository with others, since their history will retain every overwritten commit, thus rending their work out of sync with the remote repository.

As a rule of thumb, only force push when:

  • Nobody except you pulled the changes you are trying to overwrite
  • You can force everyone to clone a fresh copy after the forced push and make everyone apply their changes to it (people may hate you for this).