You use sand to generate grip, releasing the brake gently and apply power/throttle slowly. If you open the throttle too much, the wheels will spin and you'll damage the locomotive. Don't apply enough power/throttle and the train will roll back down. It takes skill but is honestly no different driving a car and doing a hill start. Same technique.
Edited to add: https://www.youtube.com/watch?v=P3660SX1_oE
This is a Garrett type locomotive on the Welsh Highland Railway. They are the most powerful steam locomotive type on 2ft gauge. Beddgelert station is on quite a gradient and makes for a challenging restart.