Make an electromagnet attract and repel
For a magnet to repulse something, that something needs to also be magnetized and the like poles of the two magnets aligned.

The electromagnet attracted everything magnetic because those other things weren't polarized with their own magnetic fields.  Two electromagnets, or the electromagnet with a permanent magnet would work.