Two sources may help answerr this to some extent.
[1] An article on the 'Scientific American' website discussed this issue in June 1998: "How is electricity from different generators synchronized so that it can be combined to service the same grid?"
The aricle gives some information, though not full information, I think. It does imply that there is a degree of automatic (phase) alignment through the magnetic fields associated with each generator.
Also given is the information that "In high-voltage transmission lines (those over approximately 100 kilovolts), [the] inductive impedance is greater than the effect of resistance by at least a factor of 10 and more likely, 20", and that there are phase delays, "that is, the receiving-end voltage lags behind the sending-end voltage". Also, at switching stations, "measurements such as voltage and voltage phase angles are made. For power to flow on the network or grid, each bus must be somewhat out of phase with other buses."
But the article does not explain, for example, what is done with those measurements. So while that article goes perhaps a little further than the information on here so far, it probably is not complete enough to satify the questioner.
[2] Then L Teschler (2019), 'How AC Power Sources Get Synchronized', says that "When a generator" {i.e. one of many in an a.c. grid} "is powered down for maintenance or even temporarily disconnected, it must resynchronize upon rejoining the grid, generally by automatic means with manual backup instrumentation in place if needed." Specifically, a generator about to be connected "must match {the grid} in voltage, frequency, phase, and phase sequence. And, of course, they must both be sine waves. In the case of phase, “synchronization” is defined as being within one electrical degree of the grid phase."
Synchronization is established with the individual generator still
electrically isolated. Another requirement for ac synchronization of
rotating generators is that generators added to the grid must have the
proper droop speed (that is the difference between rated rpm and
actual speed) so the shared load is in correct proportion to their
respective ratings. The droop speed applies to the prime mover. This
is a necessary requirement because the loading of a generator reduces
its speed, which in turn precisely determines the frequency. It is
possible for generators connected in parallel to rotate at
incrementally different speeds because the output frequency of each is
also a function of the number of poles.
To synchronize a single a.c. generator into an operating network, one
must manipulate the new unit so its voltage and frequency are a close
match to the overall network. Then the generator can be electrically
connected. When connected, it will automatically lock onto the larger
network and thereafter maintain synchronization without further
adjustment. When a single small generator connects to a larger grid,
every constituent generator changes its frequency output slightly to
accommodate the added member, which adjusts to a far greater degree.
There are over 500 individual utilities supplying the North American
grid, some having extensive banks of generators, all synchronized. The
grid is divided into several segments, connected by high-voltage
d.c. links, obviating the need for these large a.c. segments to
synchronize with one another.
The article mentions the circuit breakers through which the units connect, and their ability to act quickly to prevent the damages that might occur through mismatch.
It also describes a very old manual matching method used in the early days of a.c. 3-phase power networks, which used to use triples of incandescent lamp bulbs as phase indicators; and a slightly more recent manual matching method using a "synchroscope". Further, --
Fully automatic synchronization originally depended upon
electromechanical synchronizing relays. Currently, highly reliable
microprocessors have taken over, although lamps and synchroscopes
remain in place for monitoring and backup purposes.
A synchro check relay is inserted as an added precaution. It operates
automatically to prevent interconnection in the event of excessive
phase error.
All machines remain synchronized when the load changes within specific
limits. An excessive change in system frequency, however, can cause
constituent members to fall out of synch. Automatic disconnection then
takes place, and this can cause a temporary power outage until the
machines resynchronize.
For feeding renewable energy into the supplies in synch:
Renewable energy sources generate power via inverters that convert dc
from, say, a solar array ... In the case of wind turbines, the turbine
powers an ac generator whose frequency varies in proportion to wind
energy. This varying frequency is generally converted to dc and then
to constant-frequency ac that is grid compatible.
Of course, the connected ac must be synchronized to the grid. This
takes place by means of a special kind of inverter called a
synchronous inverter. Unlike an ac generator that is synchronized with
another generator or into the grid, the synchronous inverter
continuously samples the utility ac and synthesizes an output to
match, copying the utility waveform with regard to voltage, frequency
and phase angle.
The synchronous inverter is complex but the price has dropped as
increasing numbers of units are sold.