There are two processes you can go through if your medical is denied - one is to appeal the denial to the FAA (which you'd do if your AME messed up and you can prove they're wrong), the other is to reapply (which is probably what you'll want to do if you get denied).
When you reapply you're basically starting the medical certification process over from the beginning. You can reapply right away if you want, but practically you would reapply when you've corrected whatever condition(s) caused you to be denied, and go back to your AME with documentation showing that your condition has been corrected (or determined to be benign).
I assume based on your question that you've had to check the "Frequent or Severe Headaches" box, so you will continue to check that box, and may require a Special Issuance medical because of that -- your AME can give you more details if you wind up in this situation.
If you do get denied talk to your AME (and any other doctors you may be seeing) about your next steps before doing anything - obviously medical issues are serious not just because they keep you out of the sky but because your health is important.
You may also want to take advantage of AOPA's Pilot Protection Services - they have folks on staff who are experts at navigating the FAA medical process and can help you out. It could be worth it if you anticipate you'll need assistance with medical certification over the long haul.