Why did Germans gain an immense military advantage during the first months of fighting in 1918?
The major reason for this is that the Germans were more ready for the war and they had a better plan. Germany had been wanting a war for some time. They had also been planning for the war. Because of this, they were ready when the war began. The Germans implemented what is known as the Schlieffen Plan, in which they left a small force in the south to resist an anticipated French invasion and then sent a large force north (through neutral countries) to catch the French by surprise and crush them.
The German plan was detailed and they were ready to carry it out. This is why they were so successful early in the fighting.