The essential factor for the initial formation of galaxies, according to both theories describing galaxy evolution (such as the hierarchical merging scenario and the top-down scenario), is:
Massive gas and dust clouds collapse.
This collapse initiates the process of galaxy formation.