One story about the origin of Ganga is that the god Vishnu once heard Shiva play the flute. Vishnu was so entranced by the music that his feet began to melt. Brahma caught the liquefied portion of Vishnu in a pot and from it created Ganga. Hence Ganga is also known as Vishnu-padi (she-who-was-born-out-of-Vishnu's-feet).
The Origin of Ganga
Originally Ganga flowed only in the heavens, but then was ordered to go down to earth. Not wanting to, she threatened to flood the whole world. The gods were so afraid of her that they sought the help of Shiva.
Shiva broke the fall of Ganga by capturing her in his mighty locks of hair. Since then, Ganga resides on top of Shiva's head as his second wife, the first being Parvati.