A steed can be made to gallop by kicking or applying a whip while riding. If successful, this will cause the mount's movement rate to randomly increase for certain types of movement. If unsuccessful, the rider will be forcefully dismounted from the steed. A rider with a high experience level on a pet with a high tameness has the greatest chance of success. Tameness is reduced slightly when kicking or whipping the mount, so use this function sparingly.
Galloping will last for 20-30 turns. Movement that benefits from the speed boost is any command that causes multiple movements, such as shift + H, 9H, _, etc. (In the sourcecode, movement that sets flags.mv will benefit from the gallop speed increase.) Each turn of galloping with eligible movement, the steeds speed is increased temporarily by either four-thirds (~1.33) or five-thirds (~1.67).
The rules for what commands are eligible for speed boosts lead to some counterintuitive strategies. If you are 1 space away from a wall and want to move up against the wall, using shift + H or 2H will give you the speed boost with no other consequences, while simply pressing H will not (if the number_pad option is on, you can use 5 and then a direction.). Moving everywhere using _ travel will give you the speed boosts, even if you're only moving 1 space each time.