Before 1871, Germany as a country didn't exist yet. Instead, there were lots of smaller states within what we now know as Germany. Some of these states had colonies, which are faraway pieces of land that they controlled and tried to make money from.
Germany's first colonial project was in what is now part of Ghana in West Africa. The state of Brandenburg-Prussia, which later became part of Germany, set up a trading post in the late 1600s. Over time, they created a colony called the Brandenburg Gold Coast.
In the 1800s, when Germany was beginning to become a unified country, many Germans wanted to join in the colonial race that was happening at the time. They wanted to have colonies like the other big European countries, such as Britain and France. Germany's first chancellor, Otto von Bismarck, wasn't very keen on colonialism, but he eventually gave in to pressure from the public.
So, Germany started to establish colonies around the world. They took over parts of what is now Togo, Tanzania, Rwanda, Burundi, Namibia, and Papua New Guinea, among other places. They also had control over some areas of China.
However, Germany's colonial projects were often brutal and oppressive. They took land from local people and forced them to work on plantations or in mines. They also committed genocide, including the killing of tens of thousands of people in what is now Namibia.
Eventually, Germany lost control of its colonies after World War I. Most of the colonies were taken over by other countries, such as Britain and France. Some people in Germany still have mixed feelings about the country's history of colonialism.