In short, giraffes' long necks are the result of generation upon generation of repeated stretching and inheritance.
According to the known swath of fossil giraffes', significant neck elongation began around 14 million years ago during the Late Miocene.