The legend of Lord Ganesha and Ganga is mentioned in various Mahapuranas and Upapurans. It is widely believed that Ganesha is the elder son of Goddess Parvati. However, Goddess Ganga also claimed the elephant headed deity as her son. Generally Ganga is considered as the foster-mother of Lord Ganesha.
Shiva Purana
According to the Shiva Purana, once Goddess Parvati could not find any of the Ganas (celestial army of Lord Shiva) to guard her abode and prevent others from entering her private chambers. She desired to take a bath. She wanted to have somebody only for herself her who would place her above everyone else. Hence, Parvati created a figure of a human child from turmeric paste which she used to wash her body. Then she immersed the figure of the child in the water of River Ganga (Ganges) and it came to life. This is the legend of the birth of Lord Ganesha. Hence the Lord is also known as Dvaimatura, meaning the One who has two mothers.
Padma Purana
The Padma Purana mentions that Ganesha was born from the fragrant oily paste that was applied all over the body of Goddess Parvati. She collected the aromatic paste removed from her body while taking bath and formed the figure of boy with elephant head. Later Goddess Parvati and Lord Shiva immersed the figure into the River Ganga. The figure gained life after it came in contact with the sacred water of river Ganga. Later all the gods assembled together and worshipped him as Lord Ganesha, the remover of obstacles.
Another Puranic legend states that once the used bath-water of Goddess Parvati was poured into the Ganges River. Then the elephant-headed Goddess Malini drank this sacred water and gave birth to a noble child with five elephant heads and four arms. Goddess Ganga claimed the infant as her own son. However Lord Shiva announced that the noble child was the son of Goddess Parvati. Shiva reduced the five elephant heads of the infant to only one head. Moreover He was assigned as the Lord of obstacles (Vigneshwara). Thus Lord Ganesha is also considered as the foster-child of Goddess Ganga.
Brahma Purana
Another popular legend related with Lord Ganesha and Ganga is mentioned in the Brahma Purana. It describes the skill of Lord Ganesha as a conspirator. The legend states that the elephant-faced Hindu god conspired against Goddess Ganga in order to please his mother, Goddess Parvati. Ganga descended from the matted locks of Lord Shiva. When Goddess Ganga flowed down from the Himalaya mountain range, she became tangled in the Hair of Shiva. Lord Shiva became fond of Ganga and gave her too much attention. As a result, Parvati, the consort of Shiva, became jealous and insecure. Goddess Parvati requested her husband to remove Ganga who was entangled in his hair. But Shiva did not pay any attention to her requests and relished the sacred waters of the Ganga in his locks. Parvati became terribly upset with the constant presence of Ganga over her husband`s head. She called her son Ganesha and expressed her mental agony. Ganesha felt sorry for his mother and decided to make things right.
Lord Ganesha realized that Gautama Maharishi was the only person who could provide help in releasing Ganga from the hair of Shiva and decided to meet the sage. The renowned sage once helped all the gods and provided them with food when there was a shortage in heaven and earth. All the gods loved him and adored Gautama. Ganesha then devised a plan along with an attendant of Parvati, named Jaya. The Lord told Jaya to take the disguise of a cow and damage the crops in the fields near the abode of the sage. Lord Ganesha took the form of a Brahmin and went to the ashrama of Gautama Maharishi. Hanesha was welcomed with great hospitality and kindness. Ganesha, in the guise of the Brahmin, raised dissension among the assemblage of the Brahmins in the ashrama.
Lord Ganesha had already instructed Jaya to the form of a cow which has reduced to a skeleton due to starvation and eat all the grains in the fields. The next day when Gautama took his cows to the field, he discovered an unknown cow which started damaging all the crops. Gautama requested the strange cow not to damage all the grains which he saved as provision. But the cow continued destroying the crops and the sage failed to prevent it.
Finally Gautama Maharishi touched the body of the cow with a single blade of grass and it immediately fell down to the ground and died. Lord Ganesha and other Brahmins rushed to the scene. Ganesha declared that it is a sin to kill a cow and as Gautama was a Brahmin he needed to be penalized to his misdeed. The sage repented his action and told Ganesha that he was willing to do anything to rectify the wrongful deed.
Then Gautama invoked Lord Brahma upon the suggestion of Lord Ganesha. Brahma also knew about the agony of Goddess Parvati due to the obsession of Lord Shiva with the Ganga. Lord Brahma told the sage that he should release the river Ganga from the matted hair of Lord Shiva and let the holy river flow down to earth. Brahma also suggested that Gautama Maharishi should then bathe in the river which will wash away his sins and purify the sage. The sage followed the instructions of Lord Brahma and released Goddess Ganga from the locks of Lord Shiva. Parvati was filled with happiness to get back her husband.