Give them something to do
One of the things a dog may do in the garden is digging. Here’s a fun fact about digging: oftentimes, dogs do it because they are bored.
So, if you want to keep Fido out of the garden, one of the things you can do is to give them something to do.
Play a fetch, take them for a walk, have toys handy, and so on. Keep them mentally stimulated and occupied and your garden will be safe.