Tribalism is a very deeply ingrained feature of human psychology. I remember reading about several studies exploring tribalism in which subjects were divided randomly into groups and then put in situations that tested their partiality to members of their own group or those of the other group. Even though the only thing the subjects had in common with others in their group was that they had been assigned to that group, that fact alone was enough to create a tribal preference among its members. Imagine how much stronger that tribal impulse is when the basis for affiliation is more tangible.
Under low-stress conditions, tribal fault lines aren’t necessarily divisive. That’s why, for instance, we hear how members of different ethnic groups or religions peacefully coexisted as neighbors prior to some upheaval. But when placed under pressure these tribal fault lines fracture and people rally around the flag of their tribe.
This stuff is hard-wired into our brains and operates at a visceral level. We will always have it. The only recourse is to develop the higher level functions that we also have which can be aware of these tendencies, recognize what triggers them, and choose to act differently.