This Thanksgiving I got stuck waiting at a crossing as a long freight train went through a crossing part way, then backed up part way, then went forward even further, then went backward again, then forward, and finally backed up far enough that it cleared the crossing and I was allowed past.
I wasn’t near a depot of any kind and it definitely was the same train because I had nothing better to do than watch the cars go by.
It’s possible that the train was spotting (i.e., dropping off) several cars on a siding somewhere beyond your field of view, like at a manufacturing plant or warehouse. It would have to pull forward far enough to clear the siding, back up part way into the siding, drop off one or more cars, pull forward, etc. Depending upon how many cars it was spotting, and on what siding or sidings, that could involve a fair amount of jockeying.