God is a creature of the human imagination, to be sure, but its ubiquity in human societies throughout our history suggests that it has always played a central role in forging and maintaining the sense of identity that makes individual members of a given social group or society fall in line and submit to the kinds of disciplines which that society requires of its members. The individual exists for the greater glory of his or her society's god, not vice versa. If it is your god's interest that you charge out of the trenches with your bayonet fixed to run into a hail of enemy fire, well, you do it, even though the odds are very strong that you will soon die, or at least be severely wounded. It is true that your god provides you certain benefits, such as comfort when thinking about death, and solace in times of stress. But these are bribes your god offers you, to persuade you to act in accordance with its own purpose.
Biology offers similar inducements, notably the pleasure attached to the reproductive act.
This is usually a useful function, though it can become abhorrent when it leads one group to try to massacre another group, or banish it. Gods, in short, are just as selfish as genes. Like genes, their only purpose is to grow. The people in the world today are the ones that carry the genes that were the winners in an ancestral battle for survival. The gods that survive today are likewise the survivors of a competition that has been going on among them, for as long as our ancestors have been human.