You would be wrong to think that the hardwired tribal impulse is limited to racism. It pops up in sports fans in what is mostly harmless choosing of sides — my school or home team against your no good team.
Of course the positive purpose for the tribal impulse is so that peoples of like kind will work together for the common good. Because, however, of the universal law of probability balance, which says that creation and good must always at some point in time be offset by destruction and bad, the negative offset of the tribal impulse is fear and hatred of the “other” — murder, war and racism. You can struggle to try and modify these negative offsets but, alas, you can never ever eliminate them.