There is a popular story on how Ganesha got an elephant head. There was an ardent devotee called Gajasura. He does severe penance Lord Shiva beheads Lord Ganesha who was guarding the entrance of Parvati Devi. He attaches elephant head of Gajasura, an ardent devotee of Lord Shiva and brings him back to life. Read it in detail.
I tried searching in some puranas and found that according to Padma Purana, Goddess Parvati creates a doll with an elephant face. According to Brahma Vaivarta Purana, Ganesha lost his head due to the vision of Shani on him and due to curse of Kashyapa on Shiva. There are other accounts of birth of Ganesha in other puranas too but I haven't found this story in aforementioned puranas.
Who is this Gajasura? Where is the story of Gajasura performing severe penance and the incidents followed viz his head attached to Ganesha mentioned?