Using a combination of bad luck and some of the more advanced git options, it is possible to mess up a centralised repository by accidentally pushing a branch and overwriting the existing branch pointer (or "head") on the server.

If you know where the head was pointing prior to that push, recovering it is a simple matter of running this on the server:

git update-ref /refs/heads/branchname commit_id

However, if you don't know the previous commit ID, then you pretty much have to dig through the history using git log.

Enabling a server-side reflog

One option to prevent this from happening is to simply enable the reflog, which is disabled by default in bare repositories, on the server.

Simply add this to your git config file on the server:

[core]  
   logallrefupdates = true

and then whenever a head is updated, an entry will be added to the reflog.

Yes! It is probably worth mentioning that "mess up" does not mean to enter an inconsistent state but to rewind history. Meanwhile, a branch's reflog is deleted whenever the branch is deleted, so the safety it provides is not perfect.
Comment by Jonathan