Answer:
Use your voice, and tell it what you didn't want it to do. Make sure you do this right after the dog did it and in the place where it happened, so the dog understands.
It is never okay to hit a dog. Rewards work better than punishment. Praise the dog every time it does what you wanted it to, and it will do it again and again.