Just repeating what’s been said above, really, but IME it’s the most useful.
Always be looking ahead; often you’ll find yourself looking at a spot about 10-30cm in front of your front wheel, but mostly you need to be looking a few metres ahead – don’t look at what you’re riding through right now, look at what’s coming up 2 seconds from now. A lot of it is on the basis of “your bike will follow where you’re looking”, kind of thing, I guess.
If you do find yourself in a rut*, my only advice is to unweight the front wheel and try to lift it over the edge. A good ‘boing’ on the forks (push down then pull the front wheel up) is how I do it although a) it’s probably not called this and b) there are probably better ways. If you can get the front wheel out, it’s a start – and with luck you may be able to pull the back wheel up and over the edge by dipping the front brake and pulling up with your feet.
*NB this may not work if you’re in a metaphorical rut with your life.