A viable formulation of gauge theory with extra generations in terms of quater-nionic fields is presented. For the theory to be acceptable, the number of generations should be equal to or greater than 4. The quark-lepton mass matrices are generalized into quaternionic matrices. It is concluded that explicit CP violation automatically disappears in both strong and weak sectors.