Porcupines, hedgehogs and echidnas all have spines. Are they related?

You are right about the spines, but these animals are not very closely related.  The Echidnas are Monotremes, or Protherians and lay eggs, while the Hedgehogs and porcupines are Eutherian mammals, which give birth to live young.
The relationship between the Hedgehogs and porcupines is also not that close.  Hedgehogs are in the order (group) Insectivora, which includes the moles and shrews.  While the porcupines are found in the order Rodentia that includes animals as diverse as mice, rats, beavers and capybaras.

The three animals that you have named, hedgehogs, porcupines and echidnas, have spines through convergent evolution.  This is the process that allows different organisms to solve similar problems even though they are not related (like evolving flight in birds and bats by modification of the forelimb).  All three are predated on by larger carnivorous animals.  By evolving so that their hair is stiff and pointed at the tip has meant that they are less likely to be eaten by foxes, big cats, or marsupial wolves, who would rather eat a juicy but less spiky dinner (bad luck for moles, capybaras and platypus).

If you want to find out more about how mammals are related see The Tree of Life Project http://tolweb.org/Mammalia

You can see the relationships of many other organisms at the main Tree of Life site.