A legend from the Ramayana speaks of King Bhagirath, who once meditated before Lord Brahma for a thousand years for the salvation of the souls of his ancestors.
Pleased with his devotion, Brahma granted him a wish; the king then requested that the Lord send the river goddess Ganges down to earth from heaven so that she could flow over his ancestors' ashes and wash their curse away and allow them to go to heaven.
Brahma granted his wish but requested that the king first pray to Shiva, for Shiva alone could support the weight of Ganga's descent.
Accordingly, King Bhagrirath prayed to Shiva, who agreed that Ganga could descend while entwined in the locks of his hair. In one variation of the story, an angry Ganga tried to drown Shiva during the descent, but the Lord powerfully held her motionless until she relented.
After meandering down through Shiva's thick matted locks, the holy river Ganges appeared on earth.
For modern Hindus, this legend is re-enacted by a ceremonial ritual known as bathing the Shiva Lingam.