God created Adam in a covenant relationship with Him. God promised him everlasting life if he would obey (represented by the tree of life), and warned him of death if he disobeyed (represented by the tree of the knowledge of good and evil). Adam represented the rest of the human race to God, and by his actions would bring good or ill to the earth. Adam brought ill, by sinning. Thus ended the covenant of works.
God formed a covenant with Noah, and through Noah with the rest of humanity (Genesis 9). God promised never to completely flood the earth with water again. The Lord re-affirmed His original commission with Adam -- mankind should go forth from the ark, multiply, and subdue the earth. God appointed the rainbow as a sign of His promise. Satan would not thwart God's redemptive plan by provoking God to destroy the human race because of sin. This was covenant number 1.
God formed a covenant with Abram of Ur, and through Abram with his descendants (Genesis 12, 15, and 17). God promised to give Abram and his descendants a land of their own, innumerable offspring, and to bless the whole world through him. Adam brought the curse, but Abram would be the means by which God would bring the blessing, to undo what Satan did. God later added a sign, circumcision, to mark Abram's line. Circumcision symbolized of the righteousness that God gives us by grace through faith (Romans 4:11-12). This was covenant number 2.
Covenant number 3 was the Law, which God gave to Israel through Moses on Mount Sinai. What was the Law? It was that complete system of moral, ceremonial/priestly, and civil commandments Moses wrote down in Exodus and Leviticus, and later re-stated in Deuteronomy.
Why did God add the Law to His foundational covenant with Abraham? For a number of reasons:
1. The Law was Israel's constitution. It gave them the legal means by which to operate as a nation. God did not want them merely to be a loose collection of tribes milling around the Middle East. They were to operate as God's nation, and so they needed laws in order to function as a nation.
2. God intended the Law to be a light to the Gentiles. The intent of the Law was to provoke admiration from the Gentiles, who would look upon Israel and say, "Who is like the Lord of Israel, who gave them just laws such as these?" In a world controlled by violence, ignorance, and injustice, a society ruled by the Law would shine like a city on a hill.
3. The Law defined "holiness" in practical, ethical terms, and in this way it revealed God's will to Israel. These laws were God's conditions for earthly blessing. In this way, the Law shone a bright light on sin. By clearly defining "righteousness", sin was clearly defined in contrast.
4. The Law served God's plan of salvation by grace, even though the Law itself didn't save. The Law illustrated how grace would save. A flawless lamb would need to shed its blood , and its blood offered up by God the representative priest, to atone for the sins of all the people. The Law also reinforced the need for God's mercy, by stripping a sinner of all hope in himself. There was no way that a reader could face the blinding light of righteousness demanded by the Law, without feeling crushed and condemned by holiness. The Law also taught the believer how to live. Once saved, the Old Testament believer continued to follow the Law, because it revealed God's will for his life.
The priestly and civil elements of the Law came to an end when Jesus died, but the moral commandments carry on into the Christian era. God's grace saves us from the curse of the commandments, but grace saves us for compliance to the commandments. Salvation from the curse does not relieve us from the responsibility of compliance.
How do we know which parts of the Law are still for us today? We know which elements of the Law carry on into the Christian era, by means of the New Testament. The New Testament, especially the book of Acts and the Epistles, tell us which parts of the Law were fulfilled in Christ's death and resurrection, which parts were for Israel's civil function (and so only serve illustrative purposes now), and which parts are now part of the system of Christian commandments for the Lord's people today.