The essential factor to the initial formation of galaxies, according to the theories describing galaxy evolution, is:
Massive gas and dust clouds collapse.
This collapse of gas and dust under the influence of gravity is a fundamental process in the formation of galaxies.