Both can help relieve headache pain. Some doctors recommend heat before getting a headache and ice once a headache is in progress. Other people find heat to be effective during a headache. So if one method doesn't work for you, try the other. In general, heat increases blood flow to head and neck muscles and can help relax them.
Ice reduces the sensitivity of pain nerve endings and can help override pain impulses.
Watch your posture. Poor posture can contribute to headaches. People who work in the same position for long periods of time are especially susceptible to this. If your job requires you to stay in a fixed position, be sure to stretch, stand up, move around and take breaks every hour or so. Stretch your neck and shoulder muscles.