The word comes from Li Bai's
长干行:
郎骑竹马来,
绕床弄青梅 (the boy came riding a bamboo horse, circling the bed and playing with green plums), which gave
青梅竹马, childhood sweethearts. Online the pair is split: a girl's
竹马 is the boy she grew up with, and a boy's
青梅 is the girl.