The history of religion can be traced back as far as the invention of writing.
First writings can be dated back to 5500 BCE in the areas of Indus Valley, Easter Islands (Chilie) and the Central and Southeast Europe. Writings were also found in the Mesopotamia around 3400 BCE, Egypt around 3100 BCE and China around 1200 BCE. Among these writings are found indications of religion, which indicates that religion not only existed at that time but maybe even before that.
So the early civilizations set stones for religion. The religion of the mesopotamia and the Indus Valley were the earlier religions. Between 3200 and 3000 BCE the Newgrange in Ireland and the Stonehenge in UK were began to built. Between 2600 and 2000 BCE the pyramids were built, religious texts were written in Ancient Egypt, the Minoan civilization of the Europe worshipped variety of Goddesses.
In 2100 BCE, (21 generations after the the time of Adam and Eve), Abraham establishes a covenant with God. He becomes the father of Jewish people. After many centuries, both Christianity and Islam, were formed out of the Jewish religion. 1500 BCE was the vedic age, when the Hindu Vedas were written followed by the Upanishads a couple of centuries later. Around 1000 BCE, is probably, the time when the events of the Mahabarata took place.
During the 6th Century BCE, between 600 and 500 BCE, Jainism and Buddhism were formed. Christianity, was formed by Jesus of Nazareth, gained prominance after the death of Jesus on 30 AD. By the year 100 AD, Buddhism reached China. By 380, Christianity became the official religion of Roman Empire. The Romans helped spread this religion as they expanded their Empire in the world. Prophet Mohammed was born in the year 570 and founded Islam. In the year 1467 Guru Nanak was born who founded the Sikh Religion.
There are ofcouse many more religions. Only the major or popular religions have been mentioned here but it gives a pretty good idea about how religions were formed. I guess religion would have existed from the time humans existed. Religion has lead to many events in history. It will be amazing to read in depth about the history of each and ever religion. It is a very impotant part and decisive part of a human society.
For reference and further readings: https://en.wikipedia.org/wiki/Timeline_of_religion