Depends what type of bacteria it is. Certain types can pass environmentally, on your hands during milking, from cow to cow, etc. Just follow good practices, keep the cows clean, bedding dry, use sanitizing solutions, wear gloves during milking, don't allow contamination between the mastitis...