Hamburg was the most important U-boat construction location in Germany before and during the war with 4 yards and roughly 400 U-boats launched.
Only 2 U-boat Flotillas, both training units, were stationed in Hamburg in the war. The 31st was formed there in Sept, 1943 (also based in Wilhelmshaven and Wesermünde). The 32nd Flotilla was moved to Hamburg from Königsberg in January 1945. Both units finished the war in Hamburg.
The British army captured Hamburg on 3 May, 1945. Almost 700 craft of all sizes were sunk or scuttled in the harbour, including 10 U-boats.