"Bat Masterson is said to be cool, decisive, and a bad man with a pistol." So the local paper declared when he was elected sheriff in Dodge City, Kansas during the wild west days of the late 1800s. His reputation as a killer was perhaps exaggerated, but it didn't hurt to be feared. He spent five years as a lawman, then lost an election. He left town, going back to his earlier occupation as a gambler, ending up in Tombstone, Arizona. He heard his brother was in trouble in Dodge and got on the next train. Back in town, he immediately challenged his brother's enemies. In the ensuing gunfight no one was killed, but Bat was fined $8 and told to leave town. He got out of Dodge the same night.
To "get out of Dodge" does refer to the wild Kansas town, but the phrase originated with the TV show Gunsmoke, set in that city.