Once the Torah begins telling about Jacob's sons, the bulk of the stories is about the sibling rivalry towards Joseph. Joseph gets the striped garment. Joseph has the megalomaniac dreams. Eventually the brothers have had enough of it and decide to take it out on him. They throw him in a pit and then sell him into slavery.
Before we continue onwards to Egypt with Joseph a story about Judah is interjected. KMTT's podcast about Parshat Vayeshev delves into the question what this story does here. Judah meets Tamar, gets her pregnant, wants to kill her, but then she makes him turn around and recognize her. Eventually she gives birth to Paretz the forefather of King David. Only them we will return to Joseph and follow his adventures as a slave in Egypt.
To make a long explanation short, the moment Judah recognizes Tamar is a major turn around for Judah. Before he was as rough as his brothers and this we can see in his treatment of Joseph, but as Tamar manages to get him into recognizing her, he says: You are more righteous than me. As of this moment we can see him develop as the leader, the king among his people. I always supposed why Judah turned into the most important brother and not Joseph - surely there is much more to be said about that.