You have to consider why you're moving your bishop to g5 in the first place. From the configuration you've posted, it looks like you pinned the N between your B and the opposing Q, and then at least two moves passed where he moved his B to interpose, and then advanced his h-pawn. The problem is, whether you retreat or trade pieces, N for B, you have allowed him to develop more than you, he's ready to castle, and you've wasted several moves. I usually don't play such pins unless I have a way of countering my opponents moves to block the pin, or I really do wish to trade pieces. Alternatively, you can use pins like that to give your opponent a bad position. For example, if you manage to pin the N after their same-colour B is gone from the board or cannot interpose, then if you trade N for B, you force them to either bring out their Q early, or double their pawns.
Bottom line: have a plan, don't just play "good" moves simply because they are available.
Here is a position that I struggle with. I know there are three different ways to handle this but with this configuration I seem to always lose the momentum and usually end up with a poor pawn structure further on down in the match.
I almost never chose to retreat the bishop to h4, even though that would make the King side pawns weaker if g5 to continue the attack on the bishop.
I'm wondering if the better move would be bf4. Any thoughts on this would be appreciated.