Pharaoh had been giving a revelation from God in the form of a dream. No one in his kingdom could interpret the dream for him. He was extremely angry and his cup bearer heard of Pharaoh’s dilemma. The servant remembered Joseph and the dreams he himself had in jail and how Joseph explained them. It had been a couple of years since the servant had left jail and promised to keep Joseph in mind.
It is a good thing that the servant had not helped Joseph out of the jail earlier. He may not have been able to find him he was not still in jail. Joseph is called in and tells Pharaoh what his dreams mean. Pharaoh respects this man that had told him what God was trying to share with him. Joseph made it clear it was nothing in his power but it was of God.
Joseph was placed second in command and eventually put in charge of dispersing the food during the famine. Egypt stockpiled during the 7 good years, knowing that 7 bad years were going to soon follow. They saved up enough and were ready for the famine and the other countries looking for food.
We trace it all back to Joseph being sold into slavery and being placed in prison. Joseph knew that God had a plan for his life. These circumstances were only a temporary problem in God’s plan for his life. God had shared His plan with Joseph and he knew he couldn’t stray far out of God’s will. He didn’t want to get ahead of God or fall behind.