During thunderstorm conditions the turbulence in the cloud causes the charges to separate in such a way that the negative charges concentrate in the base of the cloud. Since like charges repel, some of the negative charges on the ground are pushed down away from the surface, leaving a net positive charge on the surface.
Opposite charges attract, so the positive and negative charges are pulled toward each other.
This first, invisible stroke is called a stepped leader. As soon as the negative and positive parts of the stepped leader connect there is a conductive path from the cloud to the ground and the negative charges rush down it causing the visible stroke. The channel created by the stepped leader is full of relatively static charge, like a line of cars at a red light. When the two parts join, it is like that light turning green, and just as the cars near the light start moving first, so do the charges near the join.