If a general pattern is hard to describe, are there any examples we can trace with confidence to use as case studies?
Like, I don't know, when and how did a bunch of people living along the Nile start calling and thinking of themselves as the same group of "Egyptian" (pardon me if this example is not accurate)
Wouldn't /r/askanthropology be a better place to ask this question?
I think you're talking about two separate things here. The example of Egyptians on the Nile doesn't really work here, because the form of collective identity in ancient Egypt precedes our contemporary idea of an Egyptian nation by thousands of years. Collective identity has long existed amongst kin-groups, villages and local centres for as long as human civilization has existed, and I don't think I'm equipped to discuss it here. However, if you are asking about ethnicity itself, I can try to tackle this question.
Ethnicity is a relatively new construct, as are the ethno-national states that go along with it. The Enlightenment and the Scientific Revolution gave rise to intensive research in the hard sciences, which are based on objective criteria and classificatory systems. The application of these methods into the humanities (the 'social sciences') led to the concept that an objective classification of human populations, based on biological, racial and social traits, was possible in the same manner as, for instance, animal and plant biology. This thinking was bolstered by the colonial expansion of European powers, which increasingly felt pressured to establish the distinction between colonial subjects and citizens of the Metropole. This is the genesis of the modern concept of ethnicity.
Turning to the historical approach, there are two dominant schools of thought within the contemporary historiography on ethnicity: the constructivists and the primordialists. Constructivists believe that ethnicity is wholly artificial/constructed. For instance, in Orientalism, Edward Said proposes that the anthropological and ethnographic research of the colonial era conducted in the Middle East and East Asia is a construct of the colonial institutions Europe employed to control and colonize their subjects. Said also proposes that European powers defined their own ethnic identities in terms of their superiority over their native/subject populations. In Benedict Anderson's Imagined Communities, the author proposes that all ethnic and ethno-national communities have been constructed from the ground up through the use of collective myths and symbols. He postulates that the genesis of ethnicity can be found in the printing press, which established the means of communication and mutual construction among supra-local identities in Europe. More recently, in National Thought in Europe, Joep Leersen proposes that ethnicity is built on the premise of exclusion, rather than inclusion, into larger group.
On the other hand, the primordialists maintain that, while certain functions of ethnicity are constructed, the seed of ethnic differentiation can be found in pre-modern, pre-scientific societies. Primordialists see ethnicity and ethno-national states as naturally occurring entities, which have their roots in antiquity. The best contemporary look at primordialism comes from Sandra Joireman's National and Political Identity. She explains that primordialism is the 'older' ideological approach, which views ethnicity as inseparable with blood-ties and kinship. It should be noted here that the constructivist arguments were built out of a rejection of this 'older' traditionalist approach.
Now, you asked for a case study. I just finished a study on the Sarts of Central Asia. Sart originally meant a person of any Tajik ancestry. However, throughout the term gradually evolved in the 16th century to refer to any city-dweller, as opposed to the nomadic population. Then, in 1867, the Russians invaded Central Asia, forming the Governor-Generalship of Turkestan. Russian anthropologists and ethnographers were dispatched to the region along with colonial administrators. If you look at their scholarship (my study focused on N. I. Ostroumov's Sarty), you can see them promoting Sart as an ethnic rather than a linguistic or urban identity. Sarts are accepted as an ethnic group in Imperial Russia, and listed on the censuses as such and a 'Sart language' is standardized by Imperial Turkic linguists. Then, in the 1920s, the Bolsheviks declare 'Sart' as an imperial, colonial relic. They declare the term verboten, and insist on referring to the 'ethnic Sarts' as 'Uzbeks.' In the 1930s, Uzbekistan's borders are established, and in 1991 it becomes a sovereign country. Today the citizens of Uzbekistan are neatly compartmentalized as Uzbeks without a thought to the convoluted lineage of their ethnic/linguistic language. What does this tell us about ethnicity? That ethnicity as we know it is constantly fluid and in flux.