By my experience, the best way to get rid of that single cramp is stretching the muscle by an external force, for example with your hands or against the floor. But carefully!
How to get rid of the tendency to cramps - this is difficult. I always thought you should just take magnesium, but recently I read that cramps can be caused not only by lack of magnesium, but also by lack of calcium, iron, vinamine E or other important minerals and vitamins...
It also can be a certain movement or a certain pair of shoes that tends to produce cramps.