When did people decide to have last names and how did they commence a family tree with their names?
You may be interested in this post I wrote earlier about the history of surnames in Europe.
The TL;DR version is that people didn't really decide for themselves to adopt last names. They were instituted by lords/governments from locality to locality to aid in keeping track of taxes, landholdings, and generational debts. If you had two "John"s living on your manor, you needed a way to tell who owed you what.
There are different forms of last names in Europe going back a couple thousand years, but modern "fixed surnames" that get passed down without ever changing didn't arise in Europe until shortly after the Norman Invasion of England in 1066.
Changing from one surname system to another, or adopting them at all, was often met with pushback from the lower classes. For example, in New York in the 1680s, the English government forced the Dutch population to stop using Dutch-style patronymic surnames and adopt English-style fixed surnames, and there was a lot of opposition, so that from about 1680-1710, there are lots of instances of Dutch people using one name on English government documents and another name on Dutch Reformed church documents. When the next generation reached adulthood, having grown up under English rule, they were more amenable to using their family's new last name.
This thread touches on the history in East Asia, as answered by /u/NientedeNada, which is slightly different and I don't have any knowledge of, so maybe they can chime in.