The gastrointestinal tract harbors large and diverse populations of bacteria that vary among individuals and within individuals over time. Numerous internal and external factors can influence the contents of these microbial communities, including diet, geography, physiology, and the extent of contact among hosts. To investigate the contributions of such factors to the variation and changes in gut microbial communities, we analyzed the distal gut microbiota of individual chimpanzees from two communities in Gombe National Park, Tanzania. These samples, which were derived from 35 chimpanzees, many of whom have been monitored for multiple years, provide an unusually comprehensive longitudinal depth for individuals of known genetic relationships. Although the composition of the great-ape microbiota has been shown to codiversify with host species, indicating that host genetics and phylogeny have played a major role in its differentiation over evolutionary timescales, the geneaological relationships of individual chimpanzees did not coincide with the similarity in their gut microbial communities. However, the inhabitants from adjacent chimpanzee communities could be distinguished based on the contents of their gut microbiota. Despite the broad similarity of community members, as would be expected from shared diet or interactions, long-term immigrants to a community often harbored the most distinctive gut microbiota, suggesting that individuals retain hallmarks of their previous gut microbial communities for extended periods. This pattern was reinforced in several chimpanzees sampled over long temporal scales, in which the major constituents of the gut microbiota were maintained for nearly a decade.