Just before you do something silly.
For those of us without magical powers, that means little and often.
If you're working by yourself, do it everytime you get a drink, or whatever.
If you're working in a team, you probably need to make sure that the thing compiles, so that if someone else gets latest, they won't get a bag of errors. But other than that, as much as you can.