The partnership of dogs and humans started a long time ago, estimated during the period of Ice Age. But it dodn't happen in a blink of an eye. It was a very long time of experimentation.
Our ancestors were great enemies with the dogs' ancestors, the wolves. Wolves are social creatures. They can barely survive alone. Wolves were great hunters than humans were. But when two creatures fight against one prey, both felt they can hunt better together than against each other.
It was probably during the period when wolves felt that hunting with humans could bring them more meat, more food, and more security.