Genesis 38:28
And it came to pass, when she travailed, that the one put out his hand: and the midwife took and bound upon his hand a scarlet thread, saying, This came out first. And it came to pass, when she travailed, that the one put out his hand: and the midwife took and bound upon his hand a scarlet thread, saying, This came out first.
Genesis 38:28 stands within Genesis 37-41, which record Joseph's early life, the envy of his brothers, his sale as a slave to the Ishmaelites, his sojourn in Egypt, and God's wondrously good dealings with him through it all. Within that sequence it belongs to the account of the sin of Judah and his family, coming after Joseph was sold into Egypt and before Joseph was bought by Potiphar. It is part of an account that displays low moral standards and other sad results connected with Jacob's having more than one wife.
The record of Judah's sin to which the verse belongs exposes sin so that readers will shun it rather than excuse it. The same record shows that God offers a remedy through his love, mercy, and power.
The birth described in the verse is that of Pharez to Tamar, who acted as a harlot with her father-in-law Judah, and Pharez stands in the human ancestry of Christ. The inclusion of women with shameful histories in Christ's human ancestry offers hope to the fallen. Pharez's place in Christ's ancestry proves that the flesh Christ took concentrated all the weaknesses and sinful tendencies of fallen humanity after long physical and moral deterioration.