The reputation of garlic as a vampire repellent goes back long before Stoker's relatively recent literary creation (Dracula). Why should this be? It's true that garlic has long been associated with health and life in general, however why should it ward off vampires rather than all undead?
There are many competing theories as to the origin of the vampire story. Many have to do with disease.
A recent theory tries to associate vampirism with rabies. This works well in general however it fails to explain convincingly the position of garlic in the myth. Instead it relies on the idea of rabies sufferers becoming fixated on the smell of garlic - an idea that could just as likely apply to the smell of coffee, not a known anti-vampire tool!
Another theory is that vampirism can be seen as symbolic of mosquito bites - and garlic is known in folklore as a natural mosquito repellent.
Mosquitoes suck blood and in doing so spread disease. So do vampires. Some of the symptoms of malaria - exhaustion, fever, anemia - are reminiscent of the reputed effects of being bitten by a vampire without being totally drained or turned. Garlic is a known insect repellent which reportedly works well against mosquitoes. This would fit well with the vampire folklore.
Of course, the $64,000 question is: does garlic actually work against vampires?
Let's hope we never have to find out...