All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
First of all, you should know that it is not permissible for a man to establish an affectionate relationship with a non-Mahram woman, so you are obliged to repent to Allaah for doing so.
As regards your marriage to that woman, it seems that it was without the consent of her guardian, and the consent of the guardian is a condition for the validity of the marriage contract according to the view of the majority of the scholars . Therefore, your marriage to her is void, however, this marriage should be invalidated or that the husband [yourself] should divorce the wife. The wife signing the marriage paper has no effect on this marriage and its does not render it valid; for more benefit, please refer to Fatwa 92478.
If the second husband married her before the first marriage was invalidated, or before you divorced her, then this second marriage is void according to the consensus of the scholars . Therefore, she is obliged to observe a waiting period from this second marriage and then you may marry her with the consent of her guardian if both of you wish to continue the marital life; for more benefit, please refer to Fatwa 120395.
As regards the girl to whom she gave birth, she is not traced back to this second husband but she is traced back to you, because the children born of a controversial marriage (like yours) are traced back to the husband since it is a doubtful marriage (and the child is for the owner of the bed as clarified in Fatwa 84301).
However, it should be noted that it is not permissible for a wife to change the name of her family to the name of the family of the husband or else, because it is confirmed that the Prophet said: “Whoever attributes his fatherhood to anyone other than his (real) father or (a slave) takes someone else as his master other than his (real) master, will incur the curse of Allaah, angels and all the people.” [Ahmad and Ibn Maajah]
In addition to this, if a wife is traced back to the family of her husband then she is imitating the non-Muslims, and the Prophet said: "Whoever imitates a people is one of them." [Abu Daawood]
For more benefit, please refer to Fataawa 85803 and 89932.
Allaah Knows best.