First post here, so correct me if I'm wrong.
First of all, the German Empire was in an alliance with the Austrian-Hungarian Hapsburg empire. When the crown Prince of the A-H empire was shot and killed in Sarajevo, the A-H empire declared was against Serbia. Serbia had the backup of Russia who had several countries behind them. Germany had no choice but to chip in on A-H empires side.
Also remember that war during that period was more honorable, and most of the soldier in the first years were acutal enlisted soldiers! The general population wanted a war, and the whole of europe had been arming up for years. The shooting of Franz Ferdinand ( the A-H crown prince) just made the barrel explode. War was inevtiable.
** gonna try to add sources as soon as I get on my computer as Im currently on a plane