My main branch keeps silently rolling back months of work

Last Thursday I noticed my main branch had somehow silently rolled back months of work, there is no record of the change. I simply logged in and saw that my local has hundreds of outgoing commits. On github the last commit was marked as being in November. I push all and this morning the situation is repeated. This is extremely concerning. A version management service that randomly loses months of work is worse than useless.

This regards a private repository owned by the company I work for so I can’t link it here.

Does anyone or anything (e.g. an automated system) else have write access? If yes, make sure there haven’t been any force-pushes. That seems like the most likely explanation. You could also try to set strict branch protection rule to prevent any force pushes.

I found out who it was, but he claims to have only force pushed a branch, which he is basically the owner of. I can not understand how that would reset main. Is this normal?

No, if he force-pushed another branch that shouldn’t affect the main branch at all…

I totally agree with @airtower-luna’s suggestion: you should protect the main branch and disable force pushes, and if you can enforce code ownership on a per-branch level you’d be safer.

Force-pushing main and other baseline branches is not advisable in repositories with multiple collaborators. You should agree on a well defined and strict contribution policy regarding branches, force pushing, etc.

In many years working on GitHub, I’ve never experienced a repository corruption or random roll-backs, so I tend to think that the problem is due to unintended force push operations.

1 Like