While there are many tales around the birth of lord Ganesha here's a most common tale explaining the origin of the festival, commonly called as Ganesh Chaturthi. One of the most popular stories is about the birth of Ganesha during Goddess Parvati’s bath. As per popular myth, Goddess Parvati, had been bathing and during her bath, created Ganesha using the dirt on her body and told him to protect her and not allow anyone inside till she finished bathing.
Lord Shiva, who was not around when Ganesha was created by her, came after a while and was shocked to see a stranger waiting and guarding outside his wife’s private chamber. When Shiva tried to enter, Lord Ganesha who never knew Shiva was her husband stopped him. Following this Ganesha and in a combat Lord Shiva were involved in a fight which ultimately ended with Shiva severing Ganesha’s head.
Getting to know this huge issue,
Parvati came out to see her child and explained that he was her creation
and as Shiva could not fix the original head of Ganesha, he got the head of the
first living being, an elephant, and attached its head to his body and thus
Lord Ganesha was created.