Story of Origin of Yoga is associated with Hindu God Shiva and Ananta. In Hinduism, Ananta is the thousand headed divine serpent on whom Vishnu sleeps. Legend has it that Shiva was once narrating lessons in yoga to Goddess Parvati. Shiva was unaware of the presence of Ananta who was lying nearby.
Ananta thus listened to the entire secret teaching of Yoga. But when the divine serpent tried to slither away, He was caught by Shiva.
For his transgression and listening to teaching of Yoga Shiva decided to punish him. Shiva asked the serpent to pass the teaching to human beings.
Ananta without changing his form approached human beings to teach yoga. But people were scared of his form and ran away.
Ananta then went back to Shiva and told him about the difficulty.
Shiva then asked him to take a human form.
Ananta then took human form and came to be known as Patanjali. He then taught yoga to human beings.
Sage Patanjali is sometimes depicted as a snake with human head due to this incident.