it should be noted the republican party has not always been exclusively associated with conservatism and the democratic party has not always been exclusively associated with liberalism. both parties used to have progressive and conservative wings.
before the 1960s they were more like political structures that people used to become viable politicians. the democratic party was the system primarily for the South and major cities, the republican party was the system primarily for the North. because the democratic parts strongest base was in the south it represented the interests of white southern racists who wanted to restrict black rights in every regard after the end of slavery, and create a social hierarchy that resembled the period of slavery as closely as possible. as a result the black americans who were politically enfranchised almost always supported or joined the republican party, because it was less intently and actively trying to fukk them over (although both parties werent shyt in general at this point, the republicans were the only viable option for black voters).
civil rights legislation changed this because southern democrats who supported segregation abandoned the party. in 64 the democratic candidate supported federal measures to end segregation and the republican candidate thought it was an infringement on “states rights”

this is why 64 was the first election in which the republican party won the deep south. a long term result has been the gradual realignment of both parties - democratic party now relies on black voters and the republicans rely on southern whites. since then the parties have become much more ideological, whereas before they were less consistent.