Actually, as per, uh, magnetism, there is a 'positive' and a 'negative' - or a north and a south - pole to every electromagnet. Magnetism will only shoot something away, however, if you've managed to match up identical poles, i.e. 'south to south' or 'north to north'. Both poles, however, will draw unmagnetized steel, so you can't propel an object via a magnetic grip.
Magnetic acceleration weapons (of which the railgun is only one) exploit various properties of electromagnetism for their item propulsion. One such is the 'carousel gun', which puts a slug inside what's essentially a miniature particle accelerator - which speeds the thing up by turning magnets on and off in sequence in order to keep pulling the slug forward in a faster and faster loop, until it directs it down the barrel.