If a car is approaching us we know that its engine noise is of a higher pitch that when it is moving away. This is due to the fact that, compared to the engine noise wavelength when the car is at rest, the engine noise wave length decreases when the car is approaching us, and increases when it is moving away,
Visible light is made of waves in the electromagnetic field. The frequency of light is high -from four to seven 10 E+14 waves per second. The different frequencies in the range are seen as different colours by the human eyes. The lower frequencies appear at the red end of the spectrum and the higher at the blue end.
Let us now assume that a source on a given star emits light at a constant frequency. After a certain time depending of the distance between the star and the earth, the light will reach us. And it will reach us at the same frequency (or wavelength) that it was emitted as the gravitational effect of the galaxy is to weak to affect it.
Imagine that the star is moving towards the earth. The distance between the star and the earth decreases, so the time taken by the light to reach us is smaller. The time between two wave crests is smaller or the light frequency will be higher. And the opposite is also true is the star move way from the earth. In this case the frequency of the light reaching us is smaller.
In short when the star is moving toward us, its light spectrum is shifted
towards the blue and when the star moves away from us, its light spectrum
is moved towards the red end.