Green’s Dictionary of Slang

keep one’s hair on v.

also keep one’s skin on
[? the image of tearing out one’s hair when in a rage; or ? (though prob. a folk ety. at best) the need of members of US pioneering wagon trains to keep calm in the face of an Indian attack (were they to panic, they might well be scalped, thus losing their hair)]

[late 19C+] to keep calm, to keep one’s temper; thus get one’s hair off, to lose one’s temper.

In exclamations

keep your hair on! (also have your head on! keep your head on! ...hairs on! ...tits on! ...wool on!)

[late 19C+] calm down! don’t lose (emotional) control!