For the most part, he doesn't seem to retain clear memories of the Hulk's exploits.
In The Incredible Hulk (2008), Bruce told Betty that all he retains are fragments and images; nothing he can derive anything from.
BETTY ROSS: What is it like? When it happens, what do you experience?
BRUCE BANNER: Remember those experiments we volunteered for at Harvard? Those induced hallucinations? It's a lot like that, just a thousand times amplified. It's like someone's poured a liter of acid into my brain.
BETTY ROSS: Do you remember anything?
BRUCE BANNER: Just fragments. Images. There's too much noise. I can never derive anything out of it.
BETTY ROSS: But then it's still you inside it.
BRUCE BANNER: No. It's not.
BETTY ROSS: I don't know. In the cave, I really felt like it knew me. Maybe your mind is in there, it's just overcharged and can't process what's happening.
BRUCE BANNER: I don't want to control it. I want to get rid of it.
The Incredible Hulk (2008)
In this scene from Avengers (2012), Banner had just woken up in a crater, after having fallen from the S.H.I.E.L.D. Helicarrier as the Hulk. The dialogue isn't explicit about what he remembers, but it doesn't seem like he remembers as much as the security guard who witnessed his landing.
SECURITY GUARD: You fell out of the sky.
BRUCE BANNER: Did I hurt anybody?
SECURITY GUARD: There's nobody around here to get hurt. You did scare the hell out of some pigeons, though.
BRUCE BANNER: Lucky.
SECURITY GUARD: Or just good aim. You were awake when you fell.
BRUCE BANNER: You saw?
SECURITY GUARD: The whole thing. Right through the ceiling. Big and green and buck-ass nude.
Avengers (2012)
In this scene from Avengers: Age of Ultron (2015), Banner had recently reverted to human form after the Hulk had assisted the Avengers in a raid on Baron Strucker's Hydra base in Sokovia. Again, the dialogue isn't explicit about what he remembers, but it doesn't seem like he remembers as much as of what went on as the other Avengers.
BLACK WIDOW: Hey, the lullaby worked better than ever.
BRUCE BANNER: Just wasn't expecting a code green.
BLACK WIDOW: You hadn't been there, there would have been double the casualties. My best friend would've been a treasured memory.
BRUCE BANNER: You know, sometimes exactly what I want to hear isn't exactly what I want to hear.
BLACK WIDOW: How long before you trust me?
BRUCE BANNER: It's not you I don't trust.
BLACK WIDOW: Thor, report on the Hulk.
THOR: The gates of Hel are filled with the screams of his victims.
BRUCE BANNER: (GROANS SOFTLY)
THOR: But not the screams of the dead, of course. No, no, wounded screams. Mainly whimpering, a great deal of complaining and tales of sprained deltoids and gout.
Avengers: Age of Ultron (2015)
In Thor: Ragnarok (2017), he reverted to human form after having spent two years between Avengers: Age of Ultron and this film as the Hulk, and it didn't seem like he remembered anything of what had transpired during that period.
BRUCE BANNER: ...Thor?
THOR: Yeah.
BANNER: What happened to your hair?
THOR: Some creepy old man cut it off.
BANNER: It looks good.
THOR: Thanks.
BANNER: Where are we? How's Nat?
THOR: Nat is good, I'm sure.
BANNER: And what about Sokovia?
THOR: Sokovia?
BANNER: The city, Sokovia. Did we save it?
THOR: Banner, listen.
BANNER: What?
THOR: Sokovia. Ultron. That was two years ago.
BANNER: What are you saying? I've been Hulk for two years?
THOR: I'm afraid so.
BANNER: What the hell happened?
Thor: Ragnarok (2017)
As noted in your question, he was shown to retain knowledge of Thanos near the beginning of Avengers: Infinity War (2018). In fact, his knowledge seemed very clear in this instance, as he knew about Thanos wiping out half the population of various planets, the fact that Loki was working for Thanos in Avengers (2012), and the fact that Thanos had the Power and Space Stones.
TONY STARK: Tell me his name again.
BRUCE BANNER: Thanos. He's a plague, Tony. He invades planets. He takes what he wants. He wipes out half the population. He sent Loki. The attack on New York, that's him.
TONY STARK: This is it. What's our timeline?
BRUCE BANNER: No telling. He has the Power and Space Stones. That already makes him the strongest creature in the whole universe. If he gets his hands on all six stones, Tony...
DR. STRANGE: He could destroy life on a scale hitherto undreamt of.
Avengers: Infinity War (2018)
There's no apparent explanation for why Banner's memories of the Hulk's exploits were so clear on this occasion, when they seemed fuzzy at best in every prior instance.
It is possible that he witnessed some of the stuff he spoke of in his human form. He is in Hulk form when we last see him near the end of Thor: Ragnarok (2017), and when we first see him near the beginning of Avengers: Infinity War (2018), but there's evidently a gap in-between those scenes, where the ship the Asgardians were on, the Statesman, was boarded by Thanos and his lackeys, and some fighting presumably took place. So, for all we know, Banner could've been in human form when the ship was initially boarded.
That is pure speculation though. It's equally possible that he was in Hulk form the whole time, and just retained unusually clear memories of what occurred for some unknown reason.