There is a text written by Luther called "an den christlichen Adel deutscher Nation" (exact spelling!). So the word "deutsch" is very old. However, even from the 1848 revolution on (short-living foundation of a German Democracy that was supposed to overcome the small monarchies ("Kleinstaaten")) or from 1871 on (Foundation of the 2nd Reich), Germans didn't consider themselves as Germans at once.
Yes, it was the same German Empire, with the "Kaiser der Deutschen" from 1871 on, but people still identified themselves strongly with their Land and their respective King (Württemberg, Sachsen, Bayern, Hessen ...) or City (Hamburg, Bremen, Lübeck) that constituted the federally organized Reich. One interesting source is the author Karl May: In his adventure stories, he gave Germans mostly positive roles, but among them, all German heros were Saxonian (as the author himself). Maybe it is similar for Americans form the US: Being American but being Texan (etc.) as well.
So there was a slow transition that was not equally fast. This transition came to an end in the years around 1933. I once read that from that time on German mountaineers wrote "deutsch" as their nationality in the summit logs much more often. Previously, they preferred "bayrisch" or "sächsisch" etc. This is an interesting source because summit logs are for the voluntary mountaineering community only, so it is not influenced by the authorities claiming their citizens.