Once Narada had a desire to listen to the tales of Ganesha. Brahma replied-
“There were various Ganeshas in different Kalpas. During the period of ‘Shweta-Kalpa’, Ganesha was born to Shiva and Parvati, when they went to Kailash mountain shortly after their marriage.
“Once while going to take her bath, Parvati instructed Nandi, to stand guard at the entrance and not to allow anybody to enter the premise without her permission. Lord Shiva arrived there by chance. Despite of Nandi’s refusal to allow him, in he went inside. Parvati did not like this.
One day it happened so that Once again, Parvati wanted to take her bath. She made an idol from the dirt of her body. She made the idol alive and instructed him not to allow anybody without her permission. She also gave him a stick for his protection.
Incidentally lord Shiva arrived once again. He tried to enter inside but Ganesha refused to let him go inside. But when Shiva tried to go inside forcibly, Ganesha hit him with his stick. Lord Shiva became furious and ordered his ganas to kill him.
The ganas of Shiva attacked Ganesha but all of them were no match for him. After being defeated by Ganesha, the Shivaganas went to Shiva and narrated everything.
While the Shivaganas were narrating their stories, Lord Brahma, Lord Vishnu and some other deities arrived there. Lord Brahma then went to Ganesha to convince him, but as soon as Ganesha saw him he tried to attack lord Brahma. Brahma came back without achieving anything. After this lord Shiva himself came to fight Ganesha.