It's not easy, when I was really struggling with self harm the mainstream "solutions" that I saw (things like rubbing an ice cube on your skin or flicking a rubber band instead) were kind of laughable. Not to knock them completely, I mean maybe they work for some people, but if you're deep into it, it's probably going to require a lot more work to break the habit.
I think the first step is acknowledging that it is a serious addiction and that it tackling it is a holistic process. If at all possible, try to separate yourself from whatever tools (if applicable) you use to engage in self harm. This might mean tossing any razors or staying away from knives or other sharp things. Obviously you can't do this forever, but at the beginning your goal should only be to accumulate a bit of clean time by any means possible.
Once you've stopped for a bit, the next step is to find ways to "sublimate" the urges into some other activity when they do inevitably crop up. Plenty of good suggestions on this thread already, but physical activity is what's worked best for me. Then it's really just a matter of staying the course. After enough time, the urges should decrease more and more. Don't beat yourself up if you relapse, use it as an opportunity to reflect on what is or isn't working.