Yeah CETME was first, some Germans went to France after the war, then Spain, worked on a new gun based on the StG45. Eventually (after lots of iterations) the Spanish adopted the CETME in 762 NATO in the late 50s and the Germans got a few along the way. Those guns became the basis for the G3. That's the super compacted version.
If you look at the metal base/sockets on stock of the Stg44, 45, CETME and G3, the single pin at the bottom that holds them and the rough shape of TMH/lower receiver on each you can follow the lineage along pretty nicely.