To begin with, we must emphasize that a galaxy is a set of various celestial bodies such as stars, planets, comets, nebulae, black holes, etc.
All these components are linked together by the force of gravity, which prevents galaxies from "evaporating" dynamically, that is, the objects that compose it from shooting out into space. On the other hand, the permanent movement of stars and gas (that is, their kinetic energy) prevents all matter from collapsing towards the system's center since it remains in constant motion.
As we mentioned, a galaxy contains many things inside; consider that at this moment, we are all inside a galaxy, the Milky Way, which contains approximately 100,000 million stars, of which the Sun is only one of them.
Each star has, on average, a planet, which means that there are billions of planets in our galaxy, and there is likely life like ours in some of them.
In addition to the stars and planets, obviously in a galaxy are all the elements we could find in a solar system, such as Asteroids, Comets, and Natural Satellites.
However, we currently know that the main component of a galaxy is not the stars nor the cosmic dust that surrounds the interstellar medium, but rather a material that, until now, we still do not know what it is, dark matter.
Dark matter is not a type of black matter; instead, it is a type of matter that we know exists, but we do not know exactly what it is, since we cannot see or measure it in any way.
But if we can't see or measure it as we know it exists? We know that because when we measure the speed of rotation of the stars of a spiral galaxy like the Milky Way, you are continually presenting a much more speed than they should have if we only consider the visible matter, in other words, the speed of rotation of the stars in a spiral galaxy point to the fact that there must be much more matter than we can see.
That's how we realized that most of a galaxy is a type of matter that we can't see, but we know it is there.
When we talk about galaxies, we mean a set of bodies that can be classified depending on their size and shape, but in general, 5 types of principal galaxies can be differentiated.
The exact process by which galaxies form is still an open question in astrophysics. One of the theories, called the SZ model (by Searle and Zinn), suggests that small structures resembling globular clusters are formed first. Then several of these objects come together to form a small galaxy called a proto galaxy. Over time the small protogalaxies reach a size large enough to attract more stars and keep them all coupled with their gravitational pull force, to form a galaxy.