Bacteria have a solution to that too though with the use of mobile genetic elements called plasmids. So the genetics of something can float in the population with locality to its relevance. Most antibiotic resistant bacteria in hospitals get their resistance from ground dwelling bacteria people walk in with their shoes.