Dogs dig holes in the yard for a number of reasons. They may be bored, chasing animals or simply mimicking the digging you do in the garden. To stop a dog from digging holes in the yard, you must address the motives for the behavior instead of punishing the digging after the fact.
Examine the digging pattern in the yard. If the dog is digging in a path, or around trees, it may be chasing animals such as gophers or moles. Call an exterminator to come inspect your yard for pests. Have the exterminator eliminate the pest animals, and your dog will stop chasing them.
Lay large, sharp rocks in the holes your dog digs. Dogs often return to the same holes when they are bored. The presence of the rocks will deter it while you address the motives of the dog's behavior.
Keep interesting and toys outside at all times, and change the toys once a month to keep the dog interested in them. If the dog is digging out of boredom, the toys will divert the behavior.
Walk your dog twice a day, especially if the dog is young or a terrier breed that was bred to dig. Regular walking will give the dog a chance to work off the energy it uses to dig holes in the yard.
Install an insulated doghouse outside. Some dogs dig for shelter or to roll in the cool soil. The doghouse will provide warmth during cold days and shade during hot ones, preventing the dog from digging to fill those needs.