There are a few different reasons why people have the urge to self-harm, whether it is out of a need for control or to punish yourself out of self-shame, or feelings of numbness, disconnectedness, sadness, frustration, or fear. That said, there are different techniques that can be useful for your specific feelings, but many fall under one specific coping mechanism for thoughts of self-harm which is distracting yourself.
Even if it’s hard to imagine that it’s possible to cope another way when you have urges to hurt yourself, there are alternative behaviors you can put in its place. Pay attention to your patterns and triggers. Seek distractions or self-harm alternatives: color, take a shower, hug a stuffed animal or pillow, let yourself cry, go for a walk, read a book, or watch a movie. Even if you cannot resist the urge to self-harm the next time, reflect on what happened to help you understand the feelings and patterns that lead to your intense urges.