Bidirectional (two-way) repeater?
Solution 1:
I'm not necessarily sure that it is the most space-effective solution, but it's probably the method for making it look the nicest, and it's certainly the easiest: Run two wires; one each way.
Edit: As a side note; if the stations are too far away from one another, what you are planning won't work in any case; and building a rail in that fashion requires a lot of boosters. (Depending on your need for speed a rail traversable by unoccupied or freight carts requires 5-10 times as many booster tracks as one for PAX transport.)
Unless this is an automated freight line a more practical and resource-friendly approach is probably to have a couple of extra minecarts in a chest at each station.
Solution 2:
If you are only using this track one way then you can have a tripwire at the exit end so that once you're off, it will send it back automatically.
If the distance is fairly short, you can use detector rails and a delay so it will go back and forth constantly but stay at each end for a few seconds so you can catch it.
A more logical idea is to have a stop at each end of the track where you would get off and then the cart is destroyed and collected and put into a chest. When you want to leave, press a button and a dispenser drops one of the stored carts onto the track for you to get in and go. Replicate this at the other end and you shouldn't run out of carts any time soon as long as you don't repeatedly use the track in one direction.