The essential factor to the initial formation of galaxies, according to the theories describing galaxy evolution, is:
Massive gas and dust clouds collapse.
This process is critical in the formation of galaxies, as it leads to the creation of structures from which galaxies can form.