I searched a little bit and wasn't really finding the answer I was looking for with the usual required effort. I would love to hear from a historian about the subject.
Cheers
Germany was militarily occupied by the Allies for a decade after WWII, from 1945-55.
When the country was partitioned in 1949, the continuing occupation of West Germany was regulated by the Occupation Statute. It made provisions for Britain, France and the US to oversee the country's disarmament.
West Germany was given back the ability to set its own defence policy when the occupation ended in 1955.
But the Occupation Statute was superceded by a new agreement, the Convention on the Presence of Foreign Forces in the Federal Republic of Germany, signed in 1954. It set out a framework for eight NATO countries, including the US, to maintain a permanent military presence in West Germany.
This agreement regulates the presence of the US military in Germany to this day.
After WWII, Germany became the frontline in the Cold War. If you look at a map of all the US military installations in modern-day Germany, they're all in what used to be West Germany (with one in West Berlin).
The country was so strategically important to the US in the Cold War that the headquarters of United States European Command (EUCOM), which directs American forces across the entire continent, was placed in Stuttgart. And, to stick with a theme, it's still there.
There's been a big decline in the number of US personnel in Germany since the end of the Cold War in the early 1990s, as the Soviet threat dissipated and America's focus shifted to conflicts in the Middle East and elsewhere.
In 1990, there were around 200,000. Now, it's just under 40,000 (though it's hard to give a definitive number because troops are often rotated elsewhere).
The threat from Russia never fully went away, even after the end of the Soviet Union. This is why some US troops stayed in Germany after the Cold War ended; a move that - given recent events - looks pretty prescient.