This is a short guide based on my personal experience.

I infrequently pull all-nighters these days as they do not make a pleasant next-day experience. However when I do, I have found few things which helped me pull numerous all-nighters successfully and also with least amount of hangover the following day.

First and foremost you need to have a strong motivation and a good reason. During the night you will find yourself frequently questioning your logic and if you do not have a strong reason you are very likely to fail.

What to avoid
Avoid stimulating drinks like tea of coffee. They may slightly help you but in the process they will fry your nerves. So your all-nighter will not be of much use. If you are staying awake all night then you better utilize it to your benefit.

Avoid high carbohydrate food.

What helps
Take some foods during the night. Fruits are great. Complex carbohydrates or moderately fatty foods work too. Personally I prefer fruits.

Take plenty of water. It also gives you some break from work and some movement.

Music, slightly jarring to the senses, is good. Don't try soft music. They act as lullaby. However too loud music can also be distracting to your work. Use headphones to spare your neighbors.

Spalsh your face with water as frequently as you need to.

Walking helps too. In fact walking helps even when everything else fails.

Mentally continuously focus and motivate yourself to complete the work. You will find yourself getting distracted. So re-focus.

Take a bath (with cold water preferably) early in the morning to refresh yourself for the day ahead. You may find yourself slightly sluggish mentally during the day. So double-check everything you do.

PS. Another interesting article on this subject. Personally I disagree with some of his points which prompted me to write this article. Also his article is more targeted towards college students. Mine is for everyone, including myself.