If you have a garden, you understand the time, energy, and patience it takes to maintain such a beautiful, serene, and peaceful space. The last thing you want to have happen is for your dog to trample through it, ruining the beauty. Also, if you have a garden growing food you are going to eat, the likelihood of your dog you getting to it first and ruining those vegetables is pretty high if he has access to your garden. Keeping your dog out of your garden can give you a quaint, serene place to enjoy nature's beauty and all of the hard work you put in to make it a beautiful space.
Training your dog to stay out of your garden will start with teaching your dog boundaries. Showing him a borderline of where he is allowed to go and where he is not allowed to go will be helpful in giving him boundaries. This will require practice with your dog every day, several times a day, until he understands the border of the garden is not a line he is allowed to cross. Boundary training is not too complicated but also not the easiest of commands he will learn. This will require repetition and dedication from both you and your dog. You may want to start your dog off with a leash at first before setting him free to roam your backyard near the garden on his own.
To train your dog to his boundaries and to keep him out of your garden, you are going to need a leash and some high-value treats to reward him for a job well done. You may want to invest in some simple garden flags or a temporary fence so he can visibly see the border line you are trying to convey during training. Be sure to have time and patience. Teaching him boundaries will require lots of repetition as well. Before you begin to work on boundary training with your dog, be sure he understands basic obedience commands such as 'sit', 'stay', and 'come'. You may also want to work on 'leave it' before you teach boundary training because it is a command that you can use to keep him out of the garden as well.