In the Mahābhārata (Śānti-parva 348.51–52) we can trace out the history of the Gītā as follows:
tretā-yugādau ca tato
vivasvān manave dadau
manuś ca loka-bhṛty-arthaṁ
sutāyekṣvākave dadau
ikṣvākuṇā ca kathito
vyāpya lokān avasthitaḥ
“In the beginning of the millennium known as Tretā-yuga this science of the relationship with the Supreme was delivered by Vivasvān to Manu. Manu, being the father of mankind, gave it to his son Mahārāja Ikṣvāku, the king of this earth planet and forefather of the Raghu dynasty, in which Lord Rāmacandra appeared.” Therefore, Bhagavad-gītā existed in human soci…