Why does White play g5? As a total newbie, I've been solving some medium-level problems on chesstempo. This one caught my eye. We play as Black after White's first move.
[FEN &quot;6k1/5p1p/5bp1/p7/P1r3PP/2n2N2/4NP2/1R4K1 w - - 0 1&quot;]

1. Rb8+ Kg7 2. g5

What I can't understand is why White plays g5.
It is a quite poor attack on the bishop as Black then plays Ne2, capturing the White knight and checking the king. Therefore White loses the knight and does not get to capture the bishop. Instead, White could have at least exchanged the knights:
[FEN &quot;1K/2PN/2N2n/PP3r1P/7p/1pb/pkp/6R w - - 0 1&quot;]

1. Nf6 Rf6

I this reckon to be a fine attack on h4 pawn as the White knight (which is protecting it) should be moved not to be captured by the rook. Yet, from White's viewpoint, I believe having the knights exchanged and the pawn captured is better than having the knight captured and leaving Black with all the pieces.
What is the point of such a move? What am I not seeing? Why are the moves I made (Nf6, Rf6) not right?
Black doesn't actually win a piece.
After 1.Rb8 Kg7 2.g5!? Nxe2, White will parry the check by playing 3.Kf1, when both the Bf6 and the Ne2 are under attack. You cannot save both pieces with 3...Nd4 attacking f3 and hoping for 4.Nxd4? Bxd4 because 4.gf6 is check.
As a consequence, Black wins a pawn and retains a winning position, but they don't pocket a piece.
Alternatives on the second move to 2.g5 are hardly better for White because their Pg4 is hanging with check, e.g. 2.Nxc3 Rxg4! (and not 2...Rxc3) 3.Kf1 Bxc3 with, once again, an extra pawn and a winning position.