There is an almost infinite number of groups to which a person belongs, depending on how he or she categorizes the social world.
It appears that the self is an important factor in forming impressions about new groups. Very small information about an ingroup and outgroup tends to project our own positive features onto the ingroup attributing contrastive features to outgroups. Self-imaging plays an important role in the initial exploratory stages when people become members of a new group. . Because of the centrality of the self in social perception.
Closeness to the in-group, which can be triggered simply by labelling, seems to be the main driving force for in-group favouritism, whilst out-group discrimination is determined by social distance, conflict, and competition between groups.
"In-group love" and "out-group hate", Halevy N, Bornstein G, Sagiv L, Psychol Sci. 2008 Apr; 19(4):405-11.
Abbink K, Brandts J, Herrmann B, Orzen H (2010) Intergroup Conflict and Intra-Group Punishment in an Experimental Contest Game. Am Econ Rev 100: 420–447.