Mr. Thread Starter,
To which God are we referring? The Judeo-Christian god of the Bible? Allah of the Quran? Zeuss, Apollo, Ra, The Great Spirit of the Native Americans?
If your question is "where did the concept of god or gods come from?" then I think the answer is that primitive man had an intellect which begged questions to which he had no answer. Questions such as why does the wind blow?, why do the seasons change? Why is there sometimes plenty of rain, while other times there is drought?
Superstitions abound in times of ignorance. When there were times of plenty, and they were followed by times of famine, people naturally wanted a return to the times of plenty. We gotta figure out how to do this. In the days before irrigation, it was simpler to ascribe "God did it" to all the tough questions posed in the previous paragraph. Since God did it, or gods did it, it became imperitive to appease this god, or these gods, as the case may be.
Rituals to ensure a bountiful harvest, bring the rains, keep the enemies at bay and so forth became more and more elaborate over the years eventually morphing into what we would now recognize as religions. The Azteks prayed to the Sun, as did the Egyptians. The streets flowed with the blood of those sacrificed to the gods in the land of the Inca's, all in an effort to please the gods and ensure the survival of the people and culture of the time.
Polytheism eventually lost popular sway, and we begin to see the rise of the monotheistic religions of Judaism, then later Christianity, then later still Islam. These three are now the dominant religions on the planet and we have forgotten the once powerful gods of the Ancient Greeks, Pre-Christian Romans, and the many various and sundry gods of the Egyptians, the Azteks, Inca's and the many many other cultures going back through antiquity. Now we have a lot of people fighting and killing one another over the proper way to worship the one true god. A god, interestingly enough, who didn't even exist to the learned people of Ancient Greece, or to the high priests of Ancient Egypt.
The concept of God and gods can be explained away as primitive peoples seeking answers to questions they, with their primitive grasp of the natural sciences, could not answer. It is also a source of comfort for the one species on this planet who has a sophisticated enough frontal lobe to be painfully aware of its own inevitable demise. Wolves don't sit around and debate which God or gods to worship. Wolves are busy trying to catch rabbits, who are busy trying to avoid wolves.
When humans gained the intellectual capacity to realize that each and every one of them was going to ultimately grow old and die, then gods and an afterlife was very quickly to follow. It is an uncomfortable thought to think I will at some point cease to exist. How comforting it is for me to find out that after my death here on Earth, I will continue to live forever, on a different plane of existence. And if I follow a certain set of rules, I can make that everlasting afterlife a very pleasant place to be.
Religion is indeed the opiate of the masses, as it eases the pain of the awful realization of our own demise. So the answer is twofold. Gods helped primitive man explain natural phenomenon he couldn't otherwise explain (Zeuss throwing lighting bolts down from the sky), and it helps humans to soothe the pain of their realization that they will someday die.
At least that is my opinion on the subject, your own personal opinions may vary.
B.