Lifestyle changes can help you avoid triggers and prevent headaches. You might want to try:
eating healthy food regularly and avoiding any trigger foods you have identified
drinking enough water
working on good posture
exercising regularly
techniques for managing your stress
getting the right amount of sleep every night
limiting alcohol and caffeine
There are also several preventive medicines and other treatments available. If you get headaches frequently, ask your doctor about whether these may be appropriate for you.