Well you see, several hundred years ago it was commonplace for children to be born with a condition called craniodisconnectivity, or the head loss sickness. These people could remove their heads and even swap them around amongst themselves with no ill effects, much to the disgust of the people around them.
They loved to make use of this talent: someone had lost something in the well? They would lower their head down into the water and grab the missing item with their teeth. Invading forces? What better to scare an enemy than a headless horseman? Yes, people with the head loss sickness were both disturbing and useful.
The reason the phrase "Heads up!" became so prevelent was because of the sufferers of the sickness would take their heads off in a panic whenever something was about to hit them in the head, usually holding their heads several inches up in the air and letting it hang there above their necks.
It soon became commonplace to shout "Heads up!" when there was a danger of being hit by a flying object--even among people who didn't have the sickness. As the sickness gradually became less and less common (now only being found on the small islet of Decapita) the phrase remained contantly in use, but the origin of the phrase was lost.
And that is where the phrase "Heads up!" came from.