Religions were initially invented to do two things: (1) explain all kinds of phenomena that nobody could explain before science came along, like disease, weather, ecosystems, the stars, consciousness, etc. and (2) to justify the social norms of a society.

The Bible (at least the Old Testament) was written primarily for the second reason, I believe. The Jews needed a way to justify their traditions and laws, and being somewhat supernaturally-minded because they hadn't yet learned of science, they fit their mystical God character in as the solution. It wasn't enough to just have an arbitrary rule that nobody could eat pig meat, or that homosexuals should be stoned to death, or that wives should submit unquestioningly to their husbands. They had to say that the creator/dictator of the universe commanded it, and thus they are all obliged to follow it, or else it just wouldn't make any sense.

But having read the Old Testament, I have the sneaking suspicion that the God idea was largely molded by the military leaders of the Jews to make them braver fighters when they were conquering other nations. After all, when you're killing all the men of a city, stealing their virgins and expropriating their property, it sure does help when you think you're on a divine mission explicitly ordered by the creator/dictator of the universe, who will always be watching your back to make sure you succeed (as long as you follow him in whatever he tells you to do). That does seem to be a central theme in the Old Testament: follow God unquestioningly and worship him, and he will reward you. When God says it's okay, you kill your neighbors and steal their stuff, and your reward will be the houses, wives, slaves, oxen and asses that you coveted from them (just be sure to ignore those pesky Ten Commandments when following God's orders though).