Search code examples
gitgit-push

Why git push behaves like git push --force?


Why does git push result in forced update, causing lost commits on the origin? What can be done to prevent this?

  • client side: git version 1.8.2.2
  • push.default set to simple
  • server side: gitlab 5.1.0 4854087

Based on some searching it is probably connected to the + sign in remote.origin.fetch setting, but when i clone a fresh repo, the + sign is already there (so it's not caused by me messing with the repo).


Solution

  • If you saw in the config the .mirror option, then it makes sense that a git push overrides everything:

    remote.<name>.mirror
    

    If true, pushing to this remote will automatically behave as if the --mirror option was given on the command line.

    You can do it with git config remote.backup.mirror true.

    If you have access to the remote repo settings, then you could do a:

    git config receive.denyNonFastForwards true
    

    in order to prevent those forced push.

    But this isn't yet supported on a remote repo like GitHub for instance.