Exercising may not prevent headaches, but it will help you feel better. It triggers the release of hormones called endorphins into your brain. Endorphins actually lift your mood and can decrease pain.
The Federal government recommends that everyone, whether they have headaches or not, get at least 30 minutes of exercise every day. You don't have to do that exercise all at once. You can get the same benefit whether you exercise in short bursts - say, 10 minutes at a time 3 times a day - or all at once.
But don't exercise if you have a headache. And if a headache starts while you're exercising, stop and contact your doctor.