Germany entered World War I because countries that were its allies entered the war first. Germany was eager to go to war, but it did not officially do so until it had a way to justify doing so.
Many historians feel that Germany was the main cause of WWI. They say that Germany wanted to expand its power and took aggressive actions that scared other countries in Europe. They argue that the German actions provoked other countries to form alliances against Germany. Even if Germany was the main cause of the war, it did not enter the war until other countries had already declared war on one another.
The first country to declare war in WWI was Austria-Hungary. That country issued an ultimatum to Serbia after the assassination of the Austro-Hungarian Archduke Franz Ferdinand. When Serbia rejected the ultimatum, Austria-Hungary declared war on July 28. Austria-Hungary was an ally of Germany. Russia was an ally of Serbia and it mobilized its army when Austria-Hungary declared war. It said it was mobilizing against Austria-Hungary only and not Germany, but Germany declared war on Russia anyway. It was ostensibly entering the war because Austria-Hungary was its ally and Austria-Hungary was at war with Serbia and being threatened by Russia.
Germany’s main allies in this war were Austria-Hungary and the Ottoman Empire. Bulgaria was also involved in the war on Germany’s side but was not a major player. Italy was on Germany’s side at first but switched sides because it wanted to take part of Austria-Hungary’s territory.