Gravitational force is always pulling. But, magnetic force have two types of force(push and pull).
If the north pole of one magnet lines up with the south pole of another, the magnets pull together. If the north pole of one magnet meets the north pole of another (or south meets south), the magnets push apart.
The direction of magnetic force can also be confirmed by magnetic force lines. Between the other two poles, lines appears to be connected. But between the same two poles, a lines appears not connected.