RH positive means you have a D antigen attached to your cells RH negative means you don't have a D antigen. When antigens enter the blood that aren't normally there, the body produces antibodies against the antigens.
If you are RH negative and baby is RH positive, your body will produce antibodies against the RH positive blood that can cause harm to the baby (this is an immune response). It can affect any future pregnancies as the antibodies stay in your blood once produced. It doesn't matter whether you are A, B, AB, or O. It's only your RH status that matters. So for example you can be O RH pos or O RH neg.
The anti D injection is made up of antibodies that won't harm your baby. Because you have these antibodies in your blood, your body doesn't feel the need to produce more so it won't produce the ones that can cause harm.
Early in pregnancy your baby doesn't have enough blood for this to be a problem, so you have the abti-D injection later when the baby is producing more of its own blood. You may need a jab slightly early if you have a sensitising event e.g. a blow to the stomach or an extra one after 28 weeks for the same reason. You must always let your midwife know if you have any kind of fall or bump yo the stomach.
In some areas you can have additional tests that test baby's blood group while pregnant. If baby is RH negative you don't need the jab. I don't know if all areas provide this testing just yet.
Hope that helps