The first known appearance of the word "yoga" with the same meaning as the modern term is in the Katha Upanishad, which was probably composed between the fifth and third centuries BCE.
The most comprehensive text on Yoga, the Yoga Sutras of Patanjali date to the early centuries of the Common Era; Yoga philosophy became known as one of the six orthodox philosophical schools of Hinduism in the second half of the first millennium CE.
The ultimate goals of yoga are stilling the mind and gaining insight, resting in detached awareness, and liberation from saṃsāra and duḥkha: a process (or discipline) leading to unity with the divine or with one's Self. This goal varies by philosophical or theological system.
In the classical Astanga yoga system, the ultimate goal of yoga is to achieve samadhi and remain in that state as pure awareness.