Ancient Giraffes had much shorter necks and looked more like deer. However there are two theories that suggest why and how giraffes necks evolved to become much longer as we know them today.
The Lamarck theory states that the food on the ground was scarce at the time and the giraffes would raise their necks to reach food in the trees.
Lamarck believed that giraffes originally had shorter necks and would stretch to reach the lowest leaves on the trees. Gradually, their necks would grow and develop into the long neck that we know today, and it would be passed onto its offspring.
However, Charles Darwin explained that Giraffes had a variation in the length of their necks.
The ones with the longest necks survived as they were able to reach food higher in the trees, and therefore live longer. These traits were then passed onto offspring and the giraffes with shorter necks would eventually die out due to the natural selection process.
Another theory as to why Giraffes have long necks is related the success in reproduction rates of males with long necks.