You come up with
A story on your first pass, then you tie disparate elements together, discard extraneous information, create cohesive themes, and rework sections to be more cohesive on editing passes in order to make it
THE story you want to tell.
Sometimes this editing is done in real time (I usually work this way) by knowing generally where your story needs to go and planting seeds for that where you are. This is almost never perfect, but it can do a lot to make serially-published work feel more cohesive. It definitely slows you down; you'll write a sentence, then remember you need certain information to be conveyed in that statement so you delete and rewrite it a few times, or have to go back through your story and reference moments you put in earlier to make sure you're remaining consistent, etc. etc. It's never perfect, but editing as you go like this can get you a good 70-80% of the way there sometimes.
Other times the whole thing is written out scene by scene with little to no regard for cohesion and then you go back through the whole thing and edit en masse now that you have the whole story written out and you know what's happening later. You can delete entire scenes, write entirely new ones, change phrasing, add foreshadowing, scrub out bits that didn't end up panning out into what you'd originally intended, etc. etc.
No one method is going to work for every writer, everyone's gonna have personal styles and idiosyncrasies in their writing method just like they will in their actual prose, so you just kinda mess around until you find what works for you.