This is the way I've heard it used, and where it comes from (to my knowledge)

There are two ways to make a reluctant mule or donkey (being very pig-headed animals) to move forward.

One of them is to dangle a carrot in front of its face. The carrot dangles on a string from a pole - just like a fishing pole. Mules & donkeys LOVE carrots so they go after it - going to get a treat (not realizing that it will always be a foot too far in front of them).

The same thing was done with water in the desert when the donkey or mule wouldn't move further anymore. They'd be thirsty, and go after the sloshing water gourd.

The other is to hit the mule or donkey in the ass with a stick (conceivably the pole broken in two since it is useless as a lure.)

The expression means...If you want to get somebody to do something, try to use a lure that will make them WANT to do it. Coax them with kindness.

If that doesn't work, then be prepared to use force.