Why is g5 a bad idea here?


Hi, it’s a bit of a one-move attack on the queen that chases it to a better square. The main problems are that it has seriously weakened your kingside and given the black pieces some more activity.
First, You’re allowing the black queen to come to forward to f4. The white f-pawn is pinned to the king by the bishop, so the dark-squared bishop is a nice attacking piece. Black can exploit the pin and play moves like Qg3+ Kh1, Qxh3+ picking off the loose pawns.
Black’s light-squared bishop was restricted by your pawns before, but pushing the g-pawn weakened the h5-square. This bishop can come to h5 where it can pin your knight to the queen. This is now a much better piece than it was.
As the black queen has moved from f5, it’s not blocking its f-pawn anymore, so at some point they can play f5 to force the f-file open and bring the rooks into the attack.
Basically, the king is very weak and exposed and you’ve activated the opponent’s pieces for them. I guess be careful pushing pawns in front of the king. Look at which squares you lose control of when you push pawns and how your opponent’s pieces can use them. Checking Dr. Can’s Chess Clinic on YouTube is really great for this. Lots of videos on how pawn moves affect piece activity.

The game itself shows why it's a bad idea to weaken your king.
Fun fact: black had the option to win a piece by Qxg3 on move 16, 17, 18, but both players missed all that.

g5 was weakening for the reasons that have already been mentioned but the problems started the move before - there wasn’t really any need to play 11.Bxf6 as it doesn’t accomplish anything except make your king feel a bit insecure and gives up a pin, making black’s position a lot more comfortable.
It also makes the earlier g4 move (which was a decent move at the time) look a bit redundant.

It weakens your kingside, gives up conrol under squares h5/f5, so your opponent could pin your f3 knight with Bh5 if he wanted to. Also your 16th move Ng3 literally gave up your knight as your f2 pawn is pinned. You got lucky that your opponent is not Stockfish, and didn't see it. Also, if you don't understand why you are losing, after playing the game, you can continue playing against Maximum computer from the position where you struggle with understanding. This method pretty often was helping me to understand why am I losing

The game itself shows why it's a bad idea to weaken your king.
Fun fact: black had the option to win a piece by Qxg3 on move 16, 17, 18, but both players missed all that.
You mean it shows why it's a bad idea to make terrible moves.
g4 is a perfectly fine move here. Bxf6 seems terrible and g5 is just a tactical blunder.
Assume he played h4 instead of g5 and if black responds with h5 then g5 seems perfectly playable here.
We're in 2024, the new meta is to just push pawns up to grab space.

Many of the reasons have been given.
I don't mean to suggest you shouldn't ask, but I think you can find some of the reasons yourself looking at an engine. What move does it suggest Black should respond with? Qf4. Okay, so what had you planned if Qf4? Or what happens if you just make a nondescript move there, like Qe2. Bang -- the engine gives Bh5, pinning the knight, and it's going to be very hard not to lose it. You say, oh, but I can save it with Kg2. Yes, but the engine suggests g5!, opening the position favoribly, and adding another attacker -- the f8 rook, as soon as pawns get traded (and a pawn trade can't be avoided).
So you go back and say, what happens if I don't play Qe2 and move the knight instead. Bang -- Qxg5+.
Does that help? There are positions where it can be hard to understand why an engine likes one side in a position, but at least try out some moves, and the engine will be good about showing you the concrete threats that can be found.