Dogs are the humans favourite pet ever since they started living in groups. It was not much earlier that there were no dogs on Earth. It all started about fifteen thousand years ago.
It was the time when humans started living in small groups. These groups hunted other carnivores and shared their food with each other but they were constantly watched by the wild brown wolf who searched for food in the area.
Wolf hesitate to come near humans because of more stress hormones present in their blood as compared to humans But hunger encouraged some wolf to come close to humans and eat the remains left by humans.
On the other hand, humans shared their remains of food with these new friends who provided them protection from other animals. Wolves who left living freely and started living with humans have changed into dogs of different types after many generations, according to the work they are used for, like some dogs work as guard dogs, some as searchers, some as hunters etc. Dogs the on other hand get more food, more chances to reproduce and produce young ones.
Dogs who are more beautiful or more helpful for humans are preferred the most. So after thousands of generations, they have developed in different type of dogs we see today. Who help humans in different work and protect humans from their own species of wolf from which they have evolved.