Assuming we're playing white and a bank rank mate is being threatened. Which one of the pawns (f, g, or h), in most cases, should be moved? Is there a general rule for this?
Of course, the concrete position is always more important than general "rules". However, as some guidelines of what is typically played:
- f2-f3: Rarely. It opens up a dangerous diagonal (a7-g1) and usually also the second rank (normally, the d- and e- pawns were moved early on). Even if Black can't mate directly, they can often at least kick White's king around.
- f2-f4: Occasionally, to immediately counter-attack a Black center position on e5 (if the second rank can be covered through other means).
- g2-g3: Occasionally. Also opens up a diagonal (a8-h1), but that can be okay if Black has no queen and light-squared bishop anymore to exploit it and/or if White can play their own light-squared bishop to this diagonal.
- g2-g4 or h2-h4: Occasionally. Can make sense to grab space when there are few pieces left (the pawns get vulnerable to piece attacks) or sometimes even to launch a counter-attack on Black's king.
- h2-h3: Statistically, probably the most played among the pawn moves. It creates the smallest weaknesses on paper - but as can be seen from the many alternatives, it's by far not a move that should be played in all positions. Especially not if Black controls h2 with another piece, obviously.
- No pawn move at all: The better the player, the more likely they are to try and parry the threat without actually moving pawns. Usually, moving flank pawns to open up a vital escape square for your king doesn't do anything else on the board (especially when moving to only the third rank) and can thus be seen as a waste of tempo (on top of creating structural weaknesses). Sometimes, that's a sacrifice you just have to make to prevent mate, but if there is another way (covering the checking square with a piece, blocking the way, etc.), it's often to prefer.
Adding to what @Annatar has already analyzed in-depth, you may see Grand master's saying never play f6/f3 (e.g. Ben Finegold), and take that as an unspoken rule. That is not the case. Those sayings do exist because those diagonals are often dangerous for the king(depends on the position and the existence of enemy bishop). Also, it becomes a meme :P So a little heads up to what you may see or you may have already seen, don't take those as a rule immediately.
Basically, you just have to be aware of dangerous diagonals, where the enemy can attack and the best pawn move will change accordingly.