In the Spanish Civil War, nearly all the army went with the Nationalists, while most of the navy remained loyal to the republic. That probably made a big difference in the end result, though help from Hitler and Mussolini didn’t hurt the Nationalist cause.
During the US Civil War, the army split according to state loyalty. Most of the navy stayed with the North. Probably because most of the navy’s officer corps and seamen came from northern states where there was more of a seagoing tradition. As I recall, at the beginning people were generally allowed to leave their units and move to the opposite side withouth interference.
My impression of the US military today is that nearly all the officers are conservatives. There might be more liberals among the enlisted personnel. It would probably be hard to guarantee the military’s adherence to either side.