Search code examples
gitgit-commitgit-push

Is there a danger of using "git push --force" if I am working on a project alone?


Is there a danger of using git push --force if I am working on a project alone? I know there are danger when I am working with a team. But what if I am alone?


Solution

  • The main danger when you use git push --force is indeed to loose pushed by others developers. So it should not happen.

    But you still can loose your own commits by mistake...

    As @Prihex mentioned it rightfully in the comments, in this specific case where you loose one of your own commit by mistake, you will still be able to retrieve it by looking at the git reflog of the branch that you git push --force

    PS: Also, be aware that it is a best practice to use git push --force-with-lease or git push --force-if-includes to reduce the probability to unexpectly loose commits (See documentation )