A man whose car became stuck on a railway line after taking a wrong turn while following GPS directions escaped from the vehicle moments before it was hit by a train.

The driver followed the instructions onto the tracks on O'Hea Street in Coburg, in Melbourne's inner north, at about 10:30pm.

When he realised what had happened, he tried to reverse the car but it became stuck on the tracks.

He managed to jump out of the car before the passenger train hit and escaped uninjured.

The train pushed the car about 15 metres along the track before stopping.

A local resident, Robert, said it was not the first time this had happened.

"His GPS has turned him left onto the railway lines. It looks a lot like a road at night," he said.

"It's happened before."

After hearing a "massive bang" Robert ran outside to help to help the man who was "quite shaken up".

"I ran out to rescue him [but] he wasn't there," Robert said.

"Luckily he'd gotten out in time and he was on the phone to triple-0 and watched his own car get hit.

"I'm just glad he's alright and everything is good."