Most of the mistakes you make with git can be repaired with reflog . The only exception is deleting your branch, because of course it deletes the file associated with it. If this happens, you can still find the branch again by looking at the HEAD header, but if you did not check the branch after a while (or never check the last end of the branch), then it won 'be there. But even then, you can try using git fsck --lost-found to find your dangling commits, and trawl them to find likely candidates for the branch hint.
As you have already indicated, if you run something that corrupts the .git directory, then all bets are disabled.
source share