If you think that this trick is just to scare the night creatures and vampires away, then no. At least, not speaking from a scientific and proven point of view.
However, garlic is one of the healthiest eatable vegetable known to humanity.
It can even cure insomnia!
A research showed that almost 40 million people in the States suffer from insomnia and long-term sleeping issues. Sleeping pills is something so common that every family has. But, we all know the dangers of overdosing or getting addicted to them.