Whereas man meant simply “person” or “human” in Old English (a meaning that still survives in words like manslaughter, mankind and manhandle), the word for an adult male in Old English was wer (which still survives today, oddly enough, in werewolf and virago).
The opposite of wer was wif. Despite being the origin of wife (and so only referring to married women today), it originally meant merely “adult woman”—a more general sense that survives in words like midwife and housewife.
Over time however wif gradually came to be used more specifically to refer to married women. But that meant that English needed another more general word for any adult female, regardless of marital status, to take its place. Step forward, then, the word woman—a mixture of the Old English wif and man, the adoption of which had the knock-on effect of making man the more usual term for an adult male, thereby ousting wer from the language altogether.
As for girl and boy, it might seem strange that girl was originally gender-neutral, but it’s entirely true: when Geoffrey Chaucer wrote of “the yonge gerles of the diocise” in the prologue to his Canterbury Tales, he was really talking about all “the young children of the diocese”.
Curiously, no one is entirely sure where the word girl comes from: one theory claims it comes from an Old English word, gyrela, for a robe or item of clothing, while another points to a corruption of the Latin word garrulus, meaning “chatty” or “talkative”.
As for boy, it too is something of a mystery. But given that it originally meant “servant” or “slave”, one explanation suggests it might derive from a French word, embuie, meaning “held in fetters”.
Whatever its origin, by the Middle English period boy had begun to be used exclusively of all male children, regardless of their status or employment, and in that sense it started to encroach on the meaning of girl. In response, girl became more specific and began to refer exclusively to female children. After co-existing for a time, the pair finally settled into their meanings in the late Middle Ages, and we’ve had girls and boys ever since.