In addition to careful stretching, a spin on the bike works for me. But I have to switch from the road bike to the hybrid to spin properly and loosen up.
Couple of reasons for that.
My road bike is old school, 13-24 freewheel, originally with 52/42 chain rings. I switched to 52/39 to ease the climbs. But it's still a little tough on some climbs when I need to loosen up, relax and enjoy a leisurely recovery ride.
Also, whenever I get on the road bike I tend to push myself. As soon as I warm up and the pain eases I think "Hmm... there's a tailwind. I could go for a new
PR on this next segment." Next thing I know, I've aggravated the strain again.
The hybrid has a 13-28 cassette, 30-40-50 triple. Easy to find a low-stress gear. And with the slight riser bar and upright position it's more comfortable overall. I just tend to ride it more leisurely.