By Bruce doing a lot of work to integrate his two personalities at a lab in Mexico
In She-Hulk: Attorney at Law S01E01 "A Normal Amount of Rage," Bruce reveals to Jennifer Walters (She-Hulk) that during the five-year period between Avengers: Infinity War and Avengers: Endgame, he worked on integrating his two personalities at a lab in Mexico built by Tony Stark.
Related dialogue:
Bruce: This is where I spent The Blip fixing myself and integrating
the Hulk-Banner identities.
Jennifer: In this tiny beach house lab.
Bruce: [Chuckles] Yeah. Tony built it for me a few years ago.
Bruce: Jen, I have been struggling with this for years. The best that I could do was merge my two halves. Give it time in the lab, we could possibly do the same for you.
One of the techniques Bruce teaches (or rather, tries to teach) Jennifer on "how to Hulk" is dialectical behavioral therapy, which "allows [a person] to hold two opposing truths at the same time." This most likely played a big part in how Bruce was able to merge his two personalities into "Smart Hulk," or "Smug Hulk," as Jennifer prefers to call him.
Jennifer: Teach me how to Hulk, please.
Bruce: Dialectical behavioral therapy. It allows us to hold two opposing truths at the same time. First, we're gonna practice some mindfulness with a few yoga techniques.