what does it mean when someone tells you to keep your head up?
It's a different idiomatic use of "keep your head up" than the emotional one about staying positive after a setback. It means to stay aware and pay attention. This often does involve literally keeping one's head up in order to remain alert, but there can be other aspects depending on the situation.