Once a star is born, it spends its active life somewhere on the main sequence. Its place on the main sequence is determined by its mass.
Astronomers make computer models of the evolution of stars.
Balance pressure against gravity. Compression of gas raises its temperature. Heat flows out toward the surface by photon radiation or convection. If the temperature and pressure are high enough, nuclear fusion occurs. Fusion gradually increases the amount of helium and decreases the amount of hydrogen.