I grew up with intense contact with animals of several species, and understand them pretty well. Better than I understand people, in fact.
Almost any dog I have ever met will back off if you have a stick in your hand, if you brandish it a bit and combine it with some stern vocal commands. Same with rocks, just stooping as if you're picking one up will makes most dogs think twice.
They are often testing your resolve, and if they sense they have the upper paw, they'll proceed with the attack. In that case, hit them as hard as you can.