why the earth magnetic field is opposite to the bar magnetic field?
It is because of if we assume the magnetic field of the Earth to be due to a giant bar magnet inside it then it placed vertically opposite to the geographical orientation of the Earth. So, the south the pole of the magnet is at the north pole of the Earth and the north pole of the magnet is at the south pole of the Earth. This is the reason why the magnetic field lines emanate from the south pole of the Earth and end at its north pole.
However, it wouldn't stay that way permanently. Earth goes through regular cycles of magnetic reversal, the mechanics of which is a big geological mystery.
It is just that right now the magnet is orientated in this way that we see this phenomena.