Star is formed from a huge cloud of dust and gas in space called Nebula.
Due to some shock waves in the space the gases accumulates in one place.As mass increases this attracts more gases and when the pressure at rthe center increases hydrogen fusion stars. .THis is main sequence most of the hydrogen is finished the star become a red giant. as gravity is reduced the outer layers are puffed out T the centera white dwarf remains.
Top side of picture shows the life of an average star.Bottom a massive star. picture credit slide share .net.