Gravity can keep a galaxy together, and or destroy it. At the center of most large galaxies, including our own their is a stellar black-hole. This black hole is a large one, with a mass several million times that of our own Sun. This black hole has a gravitational pull great enough to hold a galaxy together, and believe it or not the Sun actually orbits our black hole, but VERY VERY slowly.
With that being said, gravity can also destroy or combine galaxies, such as the instance with Andromeda and our galaxy, the Milky Way moving towards eachother. When our galaxies collide it will form the Milkdromeda? This galaxy would not resemble the spirals it is today, but rather a large cloud in space that has two black holes locked in the center. Hope this helps, and hope you learn something about astronomy!