Garlic is a commonly used food and folk remedy for preventing and treating colds. However, there is still insufficient clinical trial evidence regarding the effects of garlic in prevention or treatment. A single trial suggested that garlic may prevent occurrences of the common cold, but more studies are needed to validate this finding. Other studies haven't shown effectiveness of garlic as a treatment for the cold, and claims of effectiveness appear to rely largely on poor quality evidence.
Nevertheless, garlic and onions are immune-enhancing foods. They may not rapidly change your immune function quickly enough to make a difference once you become ill, but eating this family of foods on a regular basis is one of the components of super immunity.
My advice: continue to eat onions and garlic throughout the year and throughout any illness.