That one’s interesting. While the protagonist of Jack and the Beanstalk is called “Hans” in the German translation, there is actually no relation - as that tale seems to have originated in Britain.
The reason would likely be that “Hans” is a name very commonly used for male protagonists in German fairy tales around the early 19th century [when they were codified by the Brothers Grimm], without there being a clear archetype attached (despite the Wikipedia article suggesting they’re synonymous).
I’m fairly convinced many of these tales initially featured names that would have been rooted in local dialects and folklore, according to their places of origin, and were only “unified” during the transcription process, to make them more relatable and recognizable for a wider, literate audience with no connection to either.¹
The same is true for “Gretel”, by the way. Notably, Hänsel und Gretel are siblings, while Gretel is Hans’ betrothed in Der gescheite Hans.
¹Germany’s political and linguistical landscape was extremely fractured, up until the beginning of the 20th century. And while many people consider Luther’s bible translation to be the first unifying factor, it was very likely the works of the Brothers Grimm that allowed the process to pick up momentum, as children across the country were brought up listening to the same language from an early age.