Vinayakas

The  were a group of four troublesome demons who created obstacles and difficulties in Hindu mythology, but who were easily propitiated.
One theory of the origin of Ganesha is that he gradually came to prominence in connection with the .

In Puranic literature of a much later period the group of four Vināyakas was merged into one definite god named Vināyaka whom Rudra appointed as the "Leader of the Ganas" (Ganapati).  This Vināyaka-Ganapati is associated with another god called Dantin, "the one with the tusk," who is said to possess a twisted trunk () and who holds a corn-sheaf, a sugar cane, and a club.  This description of Dantin is so characteristic of the Puranic Ganapati that Heras says "we cannot resist to accept his full identification with this Vedic Dantin." The name Vināyaka is a common name for Ganesha both in the  and in Buddhist Tantras.

In the Smrti of Yājñavalkya, written in the 6th century, Vināyaka is definitely mentioned as a demon who had been exalted to the rank of a deva.  He is clearly described as elephant-headed by the 8th century.

The Mānava-Gṛhyasūtra 
The Vināyakas in their original demonic role are mentioned only in a limited number of Brahmanical texts that are essentially within only one school of the Vedas, the Kṛṣṇa Yajur Veda.
The Vināyakas are first mentioned in the Mānava-Gṛhyasūtras where they appear as four demonic creatures.  Dating for the Mānava-Gṛhyasūtra is only tentative, but P. V. Kane assigns it to a period prior to 600-300 BCE and considers that they had attained a position of authority in the 2nd century BCE.  S. Bhattachrji dates them between 600-200 BCE.  Macdonell dates them between 500-200 BCE.

Thapan concludes that the period reflected in the Vināyaka section of the Mānava-Gṛhyasūtra must have been between the end of the 3rd and early 2nd century BCE.  She based this conclusion in part on the fact that in the Mānava-Gṛhyasūtra the Vināyakas are associated with various other beings, including three of the four Buddhist lokpālas (guardians of the quarters), as well as the deities Mahādeva and Mahāsena.  Mahādeva and Mahāsena were popular gods during the Aśokan period, a time when the spread of Buddhism must have posed a challenge to adherents of the Vedic tradition. Thapan says that this association implies that "not only was Buddhism viewed inimically by the brāmaņa authors of this text..., but so were Mahādeva and Mahāsena."

The Mahābhārata 

The Vināyakas are also mentioned in the Mahābhārata where their role shows a distinct change in two different age strata of that epic.

In the Śānti Parva they are depicted as evil beings and are mentioned along with bhūtas and piśācas.  These passages may date shortly after the composition of the .
In the Anuśāsana Parva they lose their evil characterization and are worshipped as the , part of the  contingent.  These passages are certainly dated as belonging to the first one or two centuries CE.  A passage in the Sabhā Parva which mentions a being named Danti belongs to the same period.  Danti appears to be synonymous with the Mahākāya (One having a huge body) who is named along with the  as part of Śiva's entourage in the Anuśāsana Parva.

Thapan notes that almost all of the references to the Vināyakas, Danti, and their related beings do not appear in the main body of the critical edition of the Mahābhārata, but are only mentioned in the Appendices.  This means that the traditions associated with these figures were limited to only a few versions which must have been found in only specific regions.

Notes

References 

Ganesha
Demons in Hinduism