A long long time ago when Lord Shiva, was away fighting for the gods, the lady of the house, goddess Parvathi was alone at home. On one occasion, she needed someone to gaurd the house when she was going for a bath. Unable to think of an alternative, she used her powers to create a son, Ganesh. She instructed Ganesh to keep strict vigil on the entrance to the house and not to allow anyone into the house. Ganesh agreed and stayed on the strictest of strict vigils.
In the meantime Lord Shiva returned happy after a glorious victory for the gods, only to be stopped at the entrance by Ganesh. Ganesh, acting on Parvathi's orders verbatim, did not allow Shiva to enter the house. Lord Shiva was enraged beyond control and in a fit of rage slashed the head of Ganesh. In the meantime Paravti came out from her bath and was aghast at the scene. She was very very angry at her lordship for what had happened and explained him the situation.
Lord Shiva wanted to make it up to Parvathi very badly and agreed to put life back into Ganesha by putting the head of the first sleeping living creature that came in sight which was sleeping with its head to the north. He sent his soldiers to go in search of the creature. The first creature which came in sight was an elephant. So Lord Shiva re-created his son with the head of the elephant. Hence the trunk of Lord Ganesha.
Parvathi was still not totally happy with the deal and wanted more. Then Shiva granted Ganesha a boon that before beginning of any undertaking or task people would worship Lord Ganesh. Thus the reason for worship of ganesha before start of any work.