I am looking at Genesis 37. It says that Joseph was most loved of all the sons of Jacob. This is because Laban had tricked Jacob into marrying Leah when he really loved her sister Rachel. He married Rachel later, but Leah proved more fertile. Also, Jacob had sons by a couple other women. Only after all this did Rachel bear him a son, Joseph. So it is not hard to see why Joseph was his favorite.
In this chapter, Joseph is 17 years old, but he already is a dreamer. That is: he has dreams that predict fate. His dreams show that his fate is to rule over his brothers. It is possible that the name “Joseph” is not really a given name, but the title of a kind of shaman whose dreams can give counsel to a ruler. The Hebrew syllable SPH in names like Joseph and Asaph may mean a cultic dreamer. This is speculative. In Genesis 30:23-24 Rachel has her own understanding of the name.
The brothers decide to kill Joseph because of his seemingly arrogant dreams (18-20). Also, the text tells us that Joseph made a negative report about them to his father and that his father openly favored Joseph over his other sons. So this was a recipe for disaster.
But they do not kill him. According to verse 22, Reuben intervenes to save him. According to verses 26-27, it is Judah. This may reflect two different sources. The confusion between whether they sold him to the Ishmaelites or the Midianites shows that something is going on behind our text.
They sell him and cover up what they did by making Jacob think wild animals ate Joseph. Rather than take responsibility, the brothers are content to let their father live with this image and spend his life mourning his son.
Chapter 38 then breaks into the story of Joseph with a story about the origins of the tribe of Judah. This may be to help explain why Reuben, the oldest son, and Joseph, the favorite son, ended up secondary tribes to Judah, the tribe of David. This would indicate that Genesis came to be during the monarchy. The ruling tribe in very early sources may have been Reuben. Later Joseph and, in particular, Ephaim led in the north. But Genesis reflects the ultimate preeminence of the southern tribe of Judah.
The whole 12 tribe scheme may not have existed before Solomon divided Israel up into administrative districts. In Judges 5, the 12th century Song of Deborah, there are ten tribes. Judah, Levi, Simeon, Manasseh, and Gad are not among them. And as David is rising to power the northern alliance seems to consist of these polities: Gilead, Asher, Jezreel, Ephraim, and Benjamin (2 Samuel 2:13). It is interesting that, according to the Moabite stele, the king of Moab did not consider Gad an Israelite tribe even during the monarchy. Judah seems to have come into existence, or at least into prominence, late.
This would mean that the idea that Jacob had 12 sons who represented the future 12 tribes is a projection back from a time when 12 tribes existed as distinct entities. Ancient Israel was certainly a tribal society. But the tribes and alliances seem to have been more fluid than a strict 12 tribe league would reflect.
I am treating the Joseph story as an epic with a mixture of history and legend. The twelve sons of Jacob seems to be legendary. Historically, the story seems to tell us that there was a time when Reuben was the leading tribe, then a time when Joseph was, and then a time when Judah was. This story holds the point of view of the time after David when Judah was the leading tribe. But since Joseph represented the northern tribes of Ephaim and Manasseh, much of the tradition about Joseph must have originated there.
Still, those who would not go that far have some ammunition. Deuteronomy 33 and Genesis 49 seem to be very old. They both reflect the 12 tribe scheme.