Short answer: basically the same way that a man/boy get an idea to become a developer. They learn about the possibility and decide to give it a try
There are different ways. I for example read this very popular in my country book series for teenagers (now it’s a mandatory reading in schools) that had one of the main characters being a genius of computer science and IT - there was another, who was a genius in robotics, so I thought about robotics, too, cause it really seemed fun. Besides, I’m an adult now, but when I was in kindergarten, long time ago, I was learning “programming for kids” with Logo (Imagine). There were even some contests I wanted to participate in because of how much fun would moving this turtle be. In high school I had c++ programming. Now there is even more push for kids to learn programming than it was before, so there is just nearly no way for a kid to not touch it at some point - I know even my humanist/non-technical friends (like a friend who is an artist and was never ever interested in this kind of science) who touched programming and know the basics because they just had to at some point in their lives.
Also in my faculty in uni there were (mainly) two directions: computer science and Mathematics. Computer science has like 10-15% of women, while Mathematics had >50% of women (most probably because Math or Physics seem like a “safe” choice for someone who likes science but is unsure about technological/engineering career). And there is this little thing that while Math students can easily get a job after the full studies, no one will hire them after two years of uni and they all need getting a “practice” outside of uni (it could be internship or some science project). Since they need to learn programming in first two years, they often decide to get a programming internship since it’s “close enough” and the faculty accepts it (and it’s entirely possible to get a programming internship with little experience). Some of them might like it more than various other jobs that are possible after the Math course.
Also, a twist: the maintainer of Krita, Boud, is a linguist by education. How did he get an idea to become a developer?
I think it would be just fine to make sure that (1) the environment is safe, friendly and there is no prejudice, cause nobody would want to stay somewhere where they feel miserable; and (2) that girls and women of the world know that it’s a valid choice of career for them. Ad (1), I’ve seen myself a conversation in a chat of another open source project, it was something like: “We need more ladies here”, “Even if I were a lady, I wouldn’t admit it here”, “Touche”. What does it say about the environment? And Ad (2), both showing women who are already in tech careers and successful, and making programs for girls and women interested in tech etc., I think it does a great deal. But also just repeating that anyone can choose any career independent of their gender (but sometimes dependent of their other attributes) would help a lot.
Oh and btw - traditionally Ada Lovelace is considered to be the first programmer. Some time later, most programmers were women. Only later men started to push out women from the programming jobs, coincidentally this job was getting better paid.