Genesis 37-38 (ESV)
37:1 Jacob lived in the land of his father’s sojournings, in the land of Canaan.
2 These are the generations of Jacob.
Joseph, being seventeen years old, was pasturing the flock with his brothers. He was a boy with the sons of Bilhah and Zilpah, his father’s wives. And Joseph brought a bad report of them to their father. 3 Now Israel loved Joseph more than any other of his sons, because he was the son of his old age. And he made him a robe of many colors.  4 But when his brothers saw that their father loved him more than all his brothers, they hated him and could not speak peacefully to him.
5 Now Joseph had a dream, and when he told it to his brothers they hated him even more. 6 He said to them, “Hear this dream that I have dreamed: 7 Behold, we were binding sheaves in the field, and behold, my sheaf arose and stood upright. And behold, your sheaves gathered around it and bowed down to my sheaf.” 8 His brothers said to him, “Are you indeed to reign over us? Or are you indeed to rule over us?” So they hated him even more for his dreams and for his words.
9 Then he dreamed another dream and told it to his brothers and said, “Behold, I have dreamed another dream. Behold, the sun, the moon, and eleven stars were bowing down to me.” 10 But when he told it to his father and to his brothers, his father rebuked him and said to him, “What is this dream that you have dreamed? Shall I and your mother and your brothers indeed come to bow ourselves to the ground before you?” 11 And his brothers were jealous of him, but his father kept the saying in mind.
Joseph Sold by His Brothers
12 Now his brothers went to pasture their father’s flock near Shechem. 13 And Israel said to Joseph, “Are not your brothers pasturing the flock at Shechem? Come, I will send you to them.” And he said to him, “Here I am.” 14 So he said to him, “Go now, see if it is well with your brothers and with the flock, and bring me word.” So he sent him from the Valley of Hebron, and he came to Shechem. 15 And a man found him wandering in the fields. And the man asked him, “What are you seeking?” 16 “I am seeking my brothers,” he said. “Tell me, please, where they are pasturing the flock.” 17 And the man said, “They have gone away, for I heard them say, ‘Let us go to Dothan.’” So Joseph went after his brothers and found them at Dothan.
18 They saw him from afar, and before he came near to them they conspired against him to kill him. 19 They said to one another, “Here comes this dreamer. 20 Come now, let us kill him and throw him into one of the pits.  Then we will say that a fierce animal has devoured him, and we will see what will become of his dreams.” 21 But when Reuben heard it, he rescued him out of their hands, saying, “Let us not take his life.”22 And Reuben said to them, “Shed no blood; throw him into this pit here in the wilderness, but do not lay a hand on him”—that he might rescue him out of their hand to restore him to his father. 23 So when Joseph came to his brothers, they stripped him of his robe, the robe of many colors that he wore. 24 And they took him and threw him into a pit. The pit was empty; there was no water in it.
25 Then they sat down to eat. And looking up they saw a caravan of Ishmaelites coming from Gilead, with their camels bearing gum, balm, and myrrh, on their way to carry it down to Egypt. 26 Then Judah said to his brothers, “What profit is it if we kill our brother and conceal his blood?27 Come, let us sell him to the Ishmaelites, and let not our hand be upon him, for he is our brother, our own flesh.” And his brothers listened to him. 28 Then Midianite traders passed by. And they drew Joseph up and lifted him out of the pit, and sold him to the Ishmaelites for twenty shekels  of silver. They took Joseph to Egypt.
29 When Reuben returned to the pit and saw that Joseph was not in the pit, he tore his clothes 30 and returned to his brothers and said, “The boy is gone, and I, where shall I go?” 31 Then they took Joseph’s robe and slaughtered a goat and dipped the robe in the blood. 32 And they sent the robe of many colors and brought it to their father and said, “This we have found; please identify whether it is your son’s robe or not.” 33 And he identified it and said, “It is my son’s robe. A fierce animal has devoured him. Joseph is without doubt torn to pieces.” 34 Then Jacob tore his garments and put sackcloth on his loins and mourned for his son many days. 35 All his sons and all his daughters rose up to comfort him, but he refused to be comforted and said, “No, I shall go down to Sheol to my son, mourning.” Thus his father wept for him. 36 Meanwhile the Midianites had sold him in Egypt to Potiphar, an officer of Pharaoh, the captain of the guard.
Judah and Tamar
38:1 It happened at that time that Judah went down from his brothers and turned aside to a certain Adullamite, whose name was Hirah.2 There Judah saw the daughter of a certain Canaanite whose name was Shua. He took her and went in to her, 3 and she conceived and bore a son, and he called his name Er. 4 She conceived again and bore a son, and she called his name Onan. 5 Yet again she bore a son, and she called his name Shelah. Judah  was in Chezib when she bore him.
6 And Judah took a wife for Er his firstborn, and her name was Tamar. 7 But Er, Judah’s firstborn, was wicked in the sight of the Lord, and theLord put him to death. 8 Then Judah said to Onan, “Go in to your brother’s wife and perform the duty of a brother-in-law to her, and raise up offspring for your brother.” 9 But Onan knew that the offspring would not be his. So whenever he went in to his brother’s wife he would waste the semen on the ground, so as not to give offspring to his brother. 10 And what he did was wicked in the sight of the Lord, and he put him to death also. 11 Then Judah said to Tamar his daughter-in-law, “Remain a widow in your father’s house, till Shelah my son grows up”—for he feared that he would die, like his brothers. So Tamar went and remained in her father’s house.
12 In the course of time the wife of Judah, Shua’s daughter, died. When Judah was comforted, he went up to Timnah to his sheepshearers, he and his friend Hirah the Adullamite. 13 And when Tamar was told, “Your father-in-law is going up to Timnah to shear his sheep,” 14 she took off her widow’s garments and covered herself with a veil, wrapping herself up, and sat at the entrance to Enaim, which is on the road to Timnah. For she saw that Shelah was grown up, and she had not been given to him in marriage. 15 When Judah saw her, he thought she was a prostitute, for she had covered her face. 16 He turned to her at the roadside and said, “Come, let me come in to you,” for he did not know that she was his daughter-in-law. She said, “What will you give me, that you may come in to me?” 17 He answered, “I will send you a young goat from the flock.” And she said, “If you give me a pledge, until you send it—” 18 He said, “What pledge shall I give you?” She replied, “Your signet and your cord and your staff that is in your hand.” So he gave them to her and went in to her, and she conceived by him. 19 Then she arose and went away, and taking off her veil she put on the garments of her widowhood.
20 When Judah sent the young goat by his friend the Adullamite to take back the pledge from the woman’s hand, he did not find her. 21 And he asked the men of the place, “Where is the cult prostitute  who was at Enaim at the roadside?” And they said, “No cult prostitute has been here.” 22 So he returned to Judah and said, “I have not found her. Also, the men of the place said, ‘No cult prostitute has been here.’” 23 And Judah replied, “Let her keep the things as her own, or we shall be laughed at. You see, I sent this young goat, and you did not find her.”
24 About three months later Judah was told, “Tamar your daughter-in-law has been immoral.  Moreover, she is pregnant by immorality.”  And Judah said, “Bring her out, and let her be burned.” 25 As she was being brought out, she sent word to her father-in-law, “By the man to whom these belong, I am pregnant.” And she said, “Please identify whose these are, the signet and the cord and the staff.” 26 Then Judah identified them and said, “She is more righteous than I, since I did not give her to my son Shelah.” And he did not know her again.
27 When the time of her labor came, there were twins in her womb. 28 And when she was in labor, one put out a hand, and the midwife took and tied a scarlet thread on his hand, saying, “This one came out first.” 29 But as he drew back his hand, behold, his brother came out. And she said, “What a breach you have made for yourself!” Therefore his name was called Perez.  30 Afterward his brother came out with the scarlet thread on his hand, and his name was called Zerah.