After a series of small victories from 1862-1871, Prussian Chancellor Otto von Bismarck formed a German state. Bismarck feared that neighbouring nations, mainly France and Austria-Hungary, might act to destroy Germany. He wanted to make alliances so that there would be a balance of powers.
The Dual Alliance
Bismarck knew that Germany could not align with France due to past wars and Britain was reluctant to align with anyone. He then made an alliance with Austria-Hungary and Russia in 1873. Russia withdrew from the alliance in 1878.
The Triple Alliance
In 1882, Germany and Austria-Hungary formed a triple alliance with Italy. In this alliance if any member was attacked by France, or two or more countries at once then the alliance would come to the aid. Italy then insisted on voiding the deal if one of the triple alliances were the aggressor. Italy then signed a deal with France pledging to help if Germany attacked them.
The Russian Reinsurance
Germany didn't want to fight a war on two fronts and was keen to make some sort of agreement with France or Russia. Because of resentment with France Germany made a treaty with Russia saying that they would both stay neutral if one was involved in a war with another party. This only lasted to 1890 though. Bismarck the German ruler was the one to end the treaty however Russia wanted to keep.
In 1890 when Bismarck resigned, the foreign policy he built began to fall apart. Germany began to build up its army at a rapid rate. Suspicious of Germany sudden need to build up their army, Britain, France and Russia strengthened their ties. Germany's new leaders could not maintain it's alliances and they were surrounded by hostile powers.
Concerned about rising powers Britain was looking for allies. It signed an agreement with Russia, France and the United Kingdom in August, 1907.