Ganesha is, on the datable evidence, a comparatively late arrival among the great Hindu gods, and the material record and the textual record disagree about how late.
Small terracotta figures with an elephant head, two arms and a rounded body survive from the first century of the common era at Ter, Pal, Verrapuram and Chandraketugarh. The earliest stone icons were carved at Mathura in Kushan times, in the second and third centuries. He emerges as a clearly recognisable deity with settled iconographic attributes in the fourth and fifth centuries, including sculptures from the Kabul region of Afghanistan and the Gardez Ganesha of the fifth century. On the textual side A.K. Narain states that there is no convincing evidence in ancient Brahmanic literature for the existence of this divinity prior to the fifth century.
That gap is worth stating rather than smoothing over. Objects showing an elephant-headed figure exist some four centuries before the literature acknowledges one. The likeliest reading is that a popular cult existed below the level of the texts that survive, and that the Sanskrit tradition admitted it late; but that is an inference, and the evidence is what it is.
The modern public festival has a documented political history. Ganesh Chaturthi was a household observance until the 1890s, when Bal Gangadhar Tilak promoted it in Maharashtra as a large public event, held in the street with processions and immersions. Colonial law restricted political assembly; it did not restrict religious festivals. The festival became a lawful way for large numbers of people to gather, organise and be addressed. It remains the largest religious event in Maharashtra, with immense clay images built for the ten days and then immersed, and the plaster and paint used in the twentieth century became a serious pollution problem that several state governments now regulate.