Like everything else in evolution there are many parts to this. Evolution is a messy set of useful characterisitics that hang around because they work (help us survive and reproduce), and the ones that make us nice to each other are no exception. At the most basic and mathematically sound level, it follows that we are going to develop facilities to identify those that appear (very important, that word!) to be more related to us than others, because they share more of our genes, and hence helping them helps increase the number of those shared genes (which is what it is all about). At the most extreme level this leads to animals self-sacrificing for their brethren (some insects even give up reproducing for that end, as a hive or nest consists of individuals with identical gene sets to the queen). In humans it leads us to self-sacrifice in war to protect those that 'appear' to be more closely related, and for parents to do the same for their apparent (again, important!) offspring.
Then for social animals (like us) there is reciprocal altruism, where we remember who has done us a favour and return it, so that we can gain a reputation and likewise benefit. This is partly why we developed such big brains, to remember all the favours and betrayals!
The most human set of characteristics though are those that enable us to function as a unrelated group, where our individual (and hence our genes) survival is best served operating as a team to compete with other teams as well as the wider environment. This is the basis of nationalism, religion, tribalism and racism, as well as the more attractive characteristics of tolerance, socialism, charity, empathy etc. What makes this so hard to understand is the non-related bit, which is why I emphasised the 'appears' and 'apparent' above, as these facilities are so powerful we use them just when we feel 'related' or 'different', or when manipulative politicians, warlords or priests press the buttons, because our detection systems are so imperfect.
A good starting point for finding out more is the book 'The Origins of Virtue' by Matt Ridley. Hope this helps!