Answer:
one car at a time
Explanation:
For each car in the shorter train* (A) ...
- train A leaves one of its cars on the offshoot
- both trains move until train B can move the car from the offshoot to the portion of track away from train A
- train B moves to allow the cycle to repeat
When there are no more train A cars in front of train B, both trains can continue on their journey.
We assume cars can be decoupled at any point in the train, so that any required order of cars can be preserved. We further assume that train B can move any one of train A's cars in addition to all of its own.
_____
* The total number of car lengths that must pass the offshoot is (at least) the product of the number of cars in both trains, so it doesn't seem to matter which train makes use of the offshoot. We choose to decouple the cars of train A so that the minimum number of cycles is required--even though each cycle is longer.