That is to say, the odor is unpleasant and so bugs avoid it. When garlic is applied to the plants you want to defend, the plant absorbs the scent of the garlic, or extra particularly the allicin in garlic. The scent is faint enough that people can’t detect it after application, however insects can.
Always purchase vegetation from a good grower who can assure their plants are wholesome. Avoid accepting vegetation from friends if there’s any chance of also getting bugs or illnesses. Examine crops carefully before planting to make sure they’re clean. Consider planting cultivars identified as immune to pests.