Answer: The most effective deterrent is to fence groundhogs (and other animals) out of the garden. Some gardeners report success using the repellent sprays or granules labeled for the animal in question, or by using a pepper wax spray applied to the plants. I should mention that groundhogs in particular have dangerous teeth and are unpredictable and can bite. If they are in an area where people frequently go then you may want to contact your local animal control authority for assistance. Here is some more information about the type of fencing you could use, there are some design features to prevent them climbing it or digging under it.
I hope this helps.
Q&A Library Searching Tips