Yoga is first mentioned by name in some 2,500-year-old Hindu religious texts called the Upanishads, but this is actually a term relating to a method of strapping horses together -- literally the origin for our word "yoke." The Upanishads use it as a metaphor for a mental prayer technique, but as far as all those weird stretches are concerned, the texts mention exactly one physical posture, and that posture is pretty much "sit in a way that makes meditation comfortable." So the word "yoga" might describe an old Hindu teaching, but then so does the word "avatar," and nobody's claiming that the James Cameron movie reflects an unbroken line of ancient sacred tradition.
The ancients must have really enjoyed the smell of unwashed crotch.
It wasn't until the 19th century that an Indian prince named Krishnaraja Wodeyar III produced something resembling what we call yoga: a manual called the Sritattvanidhi, which listed 122 poses mostly taken from Indian gymnastics. What really kicked-started modern yoga, though, was the influence of the Imperial British, who introduced Indians to the new exercise craze that was sweeping Europe at the time.
"You really should try it, Sahib. It comes from the East."