Galaxy formation is currently thought to occur with the collapse of clouds, presumed to be under the influence of a high-density region of dark matter. Simulations, as well as galaxy morphology population statistics are used to test theories. Theories have been developed regarding formation of a galaxy (e.g., spiral galaxy) via a single collapse (a monolithic collapse, for the monolithic collapse model aka top down model) or to build galaxies from smaller collapses, e.g., out of globular clusters and galaxy mergers (the bottom up model). Current thought, the Lambda-CDM model, is closer to the latter, and the initial smaller collapses occur in regions with sufficient gas and dark matter.
A collapsing (plasma) cloud must cool sufficiently to allow star formation to begin, which requires sufficient transparency to allow electromagnetic radiation to carry away energy, suggesting a maximum size of galaxy that can form, perhaps 1012 solar masses. If the temperature is sufficiently low that hydrogen becomes neutral, the cloud becomes opaque, perhaps at 108 MSun, suggesting that prior to galaxy mergers, galaxies form in a range below this.