Astro FOTD: Why Are Galaxies Spirals?
Before trying to answer that, I should point out that not all galaxies do spin, at least not enough to give them that disk-like or spiral shape. Many galaxies, including the very biggest ones, are ellipticals, and some of them have almost no spin, with the motions of their stars very nearly random.
Galaxies are believed to have formed quite early in the history of the universe when ordinary matter, having cooled enough for the electrons and nuclei to condense into neutral atoms, fell into the gravitational potential wells formed by dark matter out of primordial fluctuations, forming clouds of hydrogen and helium of about a trillion solar masses or more each. As further cooling proceeded smaller scale masses became gravitationally unstable and began collapsing within the large clouds. These clouds were not necessarily spherical, and as the cloud's gravity tugged more on one end of others, they were set spinning. Somewhat analogous forces also produce spins in stars and their planetary systems.