Look up the Green Sahara and the Sahel belt you'll get a clue to you're answer. Although a lot of west african ppl aren't from west african, as the area was forest for most of it's history. They traveled and branched out from places like central and the green sahara. https://twitter.com/WuritiUbafu/status/1356688082251227147
This shouldn't be confused that they originated in Egypt but they may have come from the Nile Valley. Or places like Sudan and other areas that sustained a livelihood for a time in Africa. Before climate changes and other factors.
"Khoi-San" and some pygmy populations had lived in places in or around west africa before the drying period started pushing, other African ethnic groups from their place in central, north and east Africa.
Hence, why almost all native ethnic populations in Africa have a origin story of migration to one degree or another. Due to the fact that the Africa landscape and it's animals was never static, so why would the ppl be?
Which is how the lower half of the Nile Valley was populated with different ethnic groups from a formerly Green Sahara from the eastern side of the Sahara. As ethnic groups from Sudan and East Africa knew the Nile river quite well before the desertification event.
The Sahara wasn't a barrier to the migration to the Mediterranean coast for "Sub-Saharan" Africans during the Holocene. The Holocene is the period preceding the current dry phase of the Sahara, just as other studies conclude.
All of which influenced what would happen in the Nile Valley. https://www.researchgate.net/publication/278664920_The_Desertification_of_the_Egyptian_Sahara_during_the_Holocene_the_Last_10000_years_and_Its_Influence_on_the_Rise_of_Egyptian_Civilization