I know quite a few children with autism (former students) who hit themselves when upset. Generally, I deal in the moment with preventing them from doing so, because it's not safe, and redirecting their behavior to something else. This may mean simply putting my hands in between their hands/head, or actually stopping them, or it might mean restraining them for a very short period, and then redirecting. I usually say a quick, firm "Stop" or "Hands down/off". Redirecting might mean a variety of things depending on why they are hitting - it could be helping them to squeeze something, hit one fist into their palm, jump up and down, use words, use photo cards.
If it happens on any kind of regular basis, I do an ABC - antecedent, behavior, consequence - chart each time it happens to figure out the pattern. What happens right before hand, what exactly is the behavior, and what is my response to it? This helps to figure out the trigger, the function of the behavior, and whether the response is appropriate or not.
The most important thing is to try to identify the trigger, so that we can stop whatever prompts the behavior. Then we need to look at our reactions to it and see if they work or not. Sometimes you only have to do this once or twice to figure out the A and C. Other times you have to do it for quite a few times.