The first and fundamental thing is to stay calm, something that only practice and training will give you.
Then it is very difficult for someone to grab you with an outstretched hand, they will always try to make a lever with their arm and get you close to their body, there it would be easier to hit with a headbutt.