gravity holds galaxies together against the general expansion of the universe. in effect, the expansion of the universe takes place between groups of galaxies, not inside those groups. gravity holds the galaxy together. the same applies to groups and clusters of galaxies, such as our local group where the milky way is, and the virgo cluster, a collection of more than 1,000 (might even be 2,000) galaxies. the gravitation is produced by the matter and energy in a galaxy or group of galaxies. everything in a galaxy moves around a centre of mass, which is also an effect of gravity.