All dogs are keen diggers. German Shepherds and sled-dog breeds, such as Siberian Huskies, regularly dig holes for shelter and to escape very cold or very hot weather. Dogs bred to hunt prey underground, such as terriers and Dachshunds, had to do some digging when out working.
Undesirable digging, a form or destructiveness in the domestic dog, has a variety of causes that need to be identified. It may be a quite obviously a firm intention to "get to the other side" where something interesting or provocative lies on the other side of the fence. Some dogs can hear the movements of rats, mice or chipmunks under the ground surface and want to investigate.
A large percentage of "digger dogs" are, however, reacting to the same sort of causal stimuli as in the case of destructive behavior. Frustration, inadequate exercise or socialization, underlying anxiety of some kind, being thrown out of the house when visitors come calling, typically if the dog has other "guest-welcoming" bad habits such as jumping up in effusive greeting or thrusting its nose into groins, or just plain boredom; any of these may be responsible.
Managing unwanted digging should first be directed at eliminating any obvious causes like those mentioned above. A dog intent on digging out to go a-wandering, often a male in search of local females, could be neutered. A nervous individual might be provided a comfortable kennel or a small hut of its own. Other persistent diggers may be let outside into a hard-floored dog run instead of being permitted to use the whole garden. If there is an area of the garden where you don't mind canine excavation, the dog can be encouraged to work there by burying toys and the like, or you could install a sand pit for the same purpose. In some cases, certainly not all, providing playthings like rubber rings, beach balls or a thick-knotted piece of rope dangling from a tree or fence can serve as effective distractions
Otherwise you will have to train your dog not to dig up the prize petunias by interrupting it, preferably in such a way that you remain unseen and thus not connected to the interruption. Two possible ways of doing this are turning on a lawn sprinkler or activating a remote-control citronella-spraying collar.
Favorite digging spots can be covered with wire netting or filled with big stones. At first, while retraining a digging dog, you will need to supervise its garden outings as much as possible. As ever, obedience training with control by command, together with lots of exercise, socializing, and game playing, are an essential part of the cure.