While German laws are strict (no one will care that you’re a foreigner and didn’t know any better if you happen to break any), there aren't really that many you might break when you go on a vacation to Germany.
Germany takes its history very seriously, and any nazi symbols, salutes, songs or material, such as flags or memorabilia, are all illegal. Don’t display any of those symbols in public (or better at all) if you don’t want to get a fine and the disrespect of people around you. Denying Holocoust is also illegal.
Keep in mind, drugs (possessing, sharing, buying) is illegal, especially remember that if you plan on exploring the nightlife of Berlin or Hamburg.
The most common thing that could cause you trouble in Germany, however, is not carrying a valid transportation ticket or not buying one at all. It might seem appealing to not pay for transportation as there is barely any control when boarding, but the chances of you getting caught are high, just as the fines for riding public transport without a valid ticket! Here you can read more about transport system in Berlin, (the points about tickets apply to all German cities and you should definitely know of them before going to Germany).