Well I'm not sure gravity always attracts but that's not because I understand why. There has to be an explanation for why the universe appears to be expanding at a greater rate and several theories have been put forward including this dark matter and dark energy which has a repulsive force. Maybe gravity making hills in space/time instead of depressions?
As for gravity and magnetism, two different forces. However the greatest minds have been trying to unify all these forces into a single equation. Einstein tried his best but didn't make it. I remember a horizon programme back in early 1970s which said they had done it when they found quarks were the smallest things but obviously they got that a little wrong.